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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 : transport_adapter_(config.rtcp_send_transport), | 177 : transport_adapter_(config.rtcp_send_transport), |
178 config_(std::move(config)), | 178 config_(std::move(config)), |
179 num_cpu_cores_(num_cpu_cores), | 179 num_cpu_cores_(num_cpu_cores), |
180 process_thread_(process_thread), | 180 process_thread_(process_thread), |
181 clock_(Clock::GetRealTimeClock()), | 181 clock_(Clock::GetRealTimeClock()), |
182 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 182 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
183 call_stats_(call_stats), | 183 call_stats_(call_stats), |
184 timing_(new VCMTiming(clock_)), | 184 timing_(new VCMTiming(clock_)), |
185 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), | 185 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), |
186 stats_proxy_(&config_, clock_), | 186 stats_proxy_(&config_, clock_), |
187 rtp_stream_receiver_(&transport_adapter_, | 187 rtp_video_stream_receiver_(&transport_adapter_, |
188 call_stats_->rtcp_rtt_stats(), | 188 call_stats_->rtcp_rtt_stats(), |
189 packet_router, | 189 packet_router, |
190 &config_, | 190 &config_, |
191 &stats_proxy_, | 191 &stats_proxy_, |
192 process_thread_, | 192 process_thread_, |
193 this, // NackSender | 193 this, // NackSender |
194 this, // KeyFrameRequestSender | 194 this, // KeyFrameRequestSender |
195 this, // OnCompleteFrameCallback | 195 this, // OnCompleteFrameCallback |
196 timing_.get()), | 196 timing_.get()), |
197 rtp_stream_sync_(this) { | 197 rtp_stream_sync_(this) { |
198 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 198 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
199 | 199 |
200 RTC_DCHECK(process_thread_); | 200 RTC_DCHECK(process_thread_); |
201 RTC_DCHECK(call_stats_); | 201 RTC_DCHECK(call_stats_); |
202 | 202 |
203 module_process_thread_checker_.DetachFromThread(); | 203 module_process_thread_checker_.DetachFromThread(); |
204 | 204 |
205 RTC_DCHECK(!config_.decoders.empty()); | 205 RTC_DCHECK(!config_.decoders.empty()); |
206 std::set<int> decoder_payload_types; | 206 std::set<int> decoder_payload_types; |
(...skipping 20 matching lines...) Expand all Loading... |
227 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 227 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
228 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 228 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
229 Stop(); | 229 Stop(); |
230 | 230 |
231 process_thread_->DeRegisterModule(&rtp_stream_sync_); | 231 process_thread_->DeRegisterModule(&rtp_stream_sync_); |
232 process_thread_->DeRegisterModule(&video_receiver_); | 232 process_thread_->DeRegisterModule(&video_receiver_); |
233 } | 233 } |
234 | 234 |
235 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 235 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
236 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 236 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
237 rtp_stream_receiver_.SignalNetworkState(state); | 237 rtp_video_stream_receiver_.SignalNetworkState(state); |
238 } | 238 } |
239 | 239 |
240 | 240 |
241 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 241 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
242 return rtp_stream_receiver_.DeliverRtcp(packet, length); | 242 return rtp_video_stream_receiver_.DeliverRtcp(packet, length); |
243 } | 243 } |
244 | 244 |
245 void VideoReceiveStream::OnRtpPacket(const RtpPacketReceived& packet) { | 245 void VideoReceiveStream::OnRtpPacket(const RtpPacketReceived& packet) { |
246 rtp_stream_receiver_.OnRtpPacket(packet); | 246 rtp_video_stream_receiver_.OnRtpPacket(packet); |
247 } | 247 } |
248 | 248 |
249 void VideoReceiveStream::SetSync(Syncable* audio_syncable) { | 249 void VideoReceiveStream::SetSync(Syncable* audio_syncable) { |
250 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 250 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
251 rtp_stream_sync_.ConfigureSync(audio_syncable); | 251 rtp_stream_sync_.ConfigureSync(audio_syncable); |
252 } | 252 } |
253 | 253 |
254 void VideoReceiveStream::Start() { | 254 void VideoReceiveStream::Start() { |
255 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 255 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
256 if (decode_thread_.IsRunning()) | 256 if (decode_thread_.IsRunning()) |
257 return; | 257 return; |
258 | 258 |
259 bool protected_by_fec = config_.rtp.protected_by_flexfec || | 259 bool protected_by_fec = config_.rtp.protected_by_flexfec || |
260 rtp_stream_receiver_.IsUlpfecEnabled(); | 260 rtp_video_stream_receiver_.IsUlpfecEnabled(); |
261 | 261 |
262 frame_buffer_->Start(); | 262 frame_buffer_->Start(); |
263 call_stats_->RegisterStatsObserver(&rtp_stream_receiver_); | 263 call_stats_->RegisterStatsObserver(&rtp_video_stream_receiver_); |
264 | 264 |
265 if (rtp_stream_receiver_.IsRetransmissionsEnabled() && protected_by_fec) { | 265 if (rtp_video_stream_receiver_.IsRetransmissionsEnabled() && |
| 266 protected_by_fec) { |
266 frame_buffer_->SetProtectionMode(kProtectionNackFEC); | 267 frame_buffer_->SetProtectionMode(kProtectionNackFEC); |
267 } | 268 } |
268 | 269 |
269 transport_adapter_.Enable(); | 270 transport_adapter_.Enable(); |
270 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; | 271 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; |
271 if (config_.renderer) { | 272 if (config_.renderer) { |
272 if (config_.disable_prerenderer_smoothing) { | 273 if (config_.disable_prerenderer_smoothing) { |
273 renderer = this; | 274 renderer = this; |
274 } else { | 275 } else { |
275 incoming_video_stream_.reset( | 276 incoming_video_stream_.reset( |
276 new IncomingVideoStream(config_.render_delay_ms, this)); | 277 new IncomingVideoStream(config_.render_delay_ms, this)); |
277 renderer = incoming_video_stream_.get(); | 278 renderer = incoming_video_stream_.get(); |
278 } | 279 } |
279 } | 280 } |
280 RTC_DCHECK(renderer != nullptr); | 281 RTC_DCHECK(renderer != nullptr); |
281 | 282 |
282 for (const Decoder& decoder : config_.decoders) { | 283 for (const Decoder& decoder : config_.decoders) { |
283 video_receiver_.RegisterExternalDecoder(decoder.decoder, | 284 video_receiver_.RegisterExternalDecoder(decoder.decoder, |
284 decoder.payload_type); | 285 decoder.payload_type); |
285 VideoCodec codec = CreateDecoderVideoCodec(decoder); | 286 VideoCodec codec = CreateDecoderVideoCodec(decoder); |
286 RTC_CHECK( | 287 RTC_CHECK(rtp_video_stream_receiver_.AddReceiveCodec(codec, |
287 rtp_stream_receiver_.AddReceiveCodec(codec, decoder.codec_params)); | 288 decoder.codec_params)); |
288 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( | 289 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( |
289 &codec, num_cpu_cores_, false)); | 290 &codec, num_cpu_cores_, false)); |
290 } | 291 } |
291 | 292 |
292 video_stream_decoder_.reset(new VideoStreamDecoder( | 293 video_stream_decoder_.reset(new VideoStreamDecoder( |
293 &video_receiver_, &rtp_stream_receiver_, &rtp_stream_receiver_, | 294 &video_receiver_, &rtp_video_stream_receiver_, |
294 rtp_stream_receiver_.IsRetransmissionsEnabled(), protected_by_fec, | 295 &rtp_video_stream_receiver_, |
| 296 rtp_video_stream_receiver_.IsRetransmissionsEnabled(), protected_by_fec, |
295 &stats_proxy_, renderer)); | 297 &stats_proxy_, renderer)); |
296 // Register the channel to receive stats updates. | 298 // Register the channel to receive stats updates. |
297 call_stats_->RegisterStatsObserver(video_stream_decoder_.get()); | 299 call_stats_->RegisterStatsObserver(video_stream_decoder_.get()); |
298 // Start the decode thread | 300 // Start the decode thread |
299 decode_thread_.Start(); | 301 decode_thread_.Start(); |
300 decode_thread_.SetPriority(rtc::kHighestPriority); | 302 decode_thread_.SetPriority(rtc::kHighestPriority); |
301 rtp_stream_receiver_.StartReceive(); | 303 rtp_video_stream_receiver_.StartReceive(); |
302 } | 304 } |
303 | 305 |
304 void VideoReceiveStream::Stop() { | 306 void VideoReceiveStream::Stop() { |
305 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 307 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
306 rtp_stream_receiver_.StopReceive(); | 308 rtp_video_stream_receiver_.StopReceive(); |
307 // TriggerDecoderShutdown will release any waiting decoder thread and make it | 309 // TriggerDecoderShutdown will release any waiting decoder thread and make it |
308 // stop immediately, instead of waiting for a timeout. Needs to be called | 310 // stop immediately, instead of waiting for a timeout. Needs to be called |
309 // before joining the decoder thread thread. | 311 // before joining the decoder thread thread. |
310 video_receiver_.TriggerDecoderShutdown(); | 312 video_receiver_.TriggerDecoderShutdown(); |
311 | 313 |
312 frame_buffer_->Stop(); | 314 frame_buffer_->Stop(); |
313 call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_); | 315 call_stats_->DeregisterStatsObserver(&rtp_video_stream_receiver_); |
314 | 316 |
315 if (decode_thread_.IsRunning()) { | 317 if (decode_thread_.IsRunning()) { |
316 decode_thread_.Stop(); | 318 decode_thread_.Stop(); |
317 // Deregister external decoders so they are no longer running during | 319 // Deregister external decoders so they are no longer running during |
318 // destruction. This effectively stops the VCM since the decoder thread is | 320 // destruction. This effectively stops the VCM since the decoder thread is |
319 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 321 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
320 // running. | 322 // running. |
321 for (const Decoder& decoder : config_.decoders) | 323 for (const Decoder& decoder : config_.decoders) |
322 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 324 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
323 } | 325 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 codec_specific_info->codecType); | 398 codec_specific_info->codecType); |
397 RTC_DCHECK(ok); | 399 RTC_DCHECK(ok); |
398 } | 400 } |
399 } | 401 } |
400 | 402 |
401 return Result(Result::OK, encoded_image._timeStamp); | 403 return Result(Result::OK, encoded_image._timeStamp); |
402 } | 404 } |
403 | 405 |
404 void VideoReceiveStream::SendNack( | 406 void VideoReceiveStream::SendNack( |
405 const std::vector<uint16_t>& sequence_numbers) { | 407 const std::vector<uint16_t>& sequence_numbers) { |
406 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); | 408 rtp_video_stream_receiver_.RequestPacketRetransmit(sequence_numbers); |
407 } | 409 } |
408 | 410 |
409 void VideoReceiveStream::RequestKeyFrame() { | 411 void VideoReceiveStream::RequestKeyFrame() { |
410 rtp_stream_receiver_.RequestKeyFrame(); | 412 rtp_video_stream_receiver_.RequestKeyFrame(); |
411 } | 413 } |
412 | 414 |
413 void VideoReceiveStream::OnCompleteFrame( | 415 void VideoReceiveStream::OnCompleteFrame( |
414 std::unique_ptr<video_coding::FrameObject> frame) { | 416 std::unique_ptr<video_coding::FrameObject> frame) { |
415 int last_continuous_pid = frame_buffer_->InsertFrame(std::move(frame)); | 417 int last_continuous_pid = frame_buffer_->InsertFrame(std::move(frame)); |
416 if (last_continuous_pid != -1) | 418 if (last_continuous_pid != -1) |
417 rtp_stream_receiver_.FrameContinuous(last_continuous_pid); | 419 rtp_video_stream_receiver_.FrameContinuous(last_continuous_pid); |
418 } | 420 } |
419 | 421 |
420 int VideoReceiveStream::id() const { | 422 int VideoReceiveStream::id() const { |
421 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 423 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
422 return config_.rtp.remote_ssrc; | 424 return config_.rtp.remote_ssrc; |
423 } | 425 } |
424 | 426 |
425 rtc::Optional<Syncable::Info> VideoReceiveStream::GetInfo() const { | 427 rtc::Optional<Syncable::Info> VideoReceiveStream::GetInfo() const { |
426 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); | 428 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
427 Syncable::Info info; | 429 Syncable::Info info; |
428 | 430 |
429 RtpReceiver* rtp_receiver = rtp_stream_receiver_.GetRtpReceiver(); | 431 RtpReceiver* rtp_receiver = rtp_video_stream_receiver_.GetRtpReceiver(); |
430 RTC_DCHECK(rtp_receiver); | 432 RTC_DCHECK(rtp_receiver); |
431 if (!rtp_receiver->Timestamp(&info.latest_received_capture_timestamp)) | 433 if (!rtp_receiver->Timestamp(&info.latest_received_capture_timestamp)) |
432 return rtc::Optional<Syncable::Info>(); | 434 return rtc::Optional<Syncable::Info>(); |
433 if (!rtp_receiver->LastReceivedTimeMs(&info.latest_receive_time_ms)) | 435 if (!rtp_receiver->LastReceivedTimeMs(&info.latest_receive_time_ms)) |
434 return rtc::Optional<Syncable::Info>(); | 436 return rtc::Optional<Syncable::Info>(); |
435 | 437 |
436 RtpRtcp* rtp_rtcp = rtp_stream_receiver_.rtp_rtcp(); | 438 RtpRtcp* rtp_rtcp = rtp_video_stream_receiver_.rtp_rtcp(); |
437 RTC_DCHECK(rtp_rtcp); | 439 RTC_DCHECK(rtp_rtcp); |
438 if (rtp_rtcp->RemoteNTP(&info.capture_time_ntp_secs, | 440 if (rtp_rtcp->RemoteNTP(&info.capture_time_ntp_secs, |
439 &info.capture_time_ntp_frac, | 441 &info.capture_time_ntp_frac, |
440 nullptr, | 442 nullptr, |
441 nullptr, | 443 nullptr, |
442 &info.capture_time_source_clock) != 0) { | 444 &info.capture_time_source_clock) != 0) { |
443 return rtc::Optional<Syncable::Info>(); | 445 return rtc::Optional<Syncable::Info>(); |
444 } | 446 } |
445 | 447 |
446 info.current_delay_ms = video_receiver_.Delay(); | 448 info.current_delay_ms = video_receiver_.Delay(); |
(...skipping 21 matching lines...) Expand all Loading... |
468 video_coding::FrameBuffer::ReturnReason res = | 470 video_coding::FrameBuffer::ReturnReason res = |
469 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); | 471 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); |
470 | 472 |
471 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { | 473 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { |
472 video_receiver_.DecodingStopped(); | 474 video_receiver_.DecodingStopped(); |
473 return false; | 475 return false; |
474 } | 476 } |
475 | 477 |
476 if (frame) { | 478 if (frame) { |
477 if (video_receiver_.Decode(frame.get()) == VCM_OK) | 479 if (video_receiver_.Decode(frame.get()) == VCM_OK) |
478 rtp_stream_receiver_.FrameDecoded(frame->picture_id); | 480 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); |
479 } else { | 481 } else { |
480 int64_t now_ms = clock_->TimeInMilliseconds(); | 482 int64_t now_ms = clock_->TimeInMilliseconds(); |
481 rtc::Optional<int64_t> last_packet_ms = | 483 rtc::Optional<int64_t> last_packet_ms = |
482 rtp_stream_receiver_.LastReceivedPacketMs(); | 484 rtp_video_stream_receiver_.LastReceivedPacketMs(); |
483 rtc::Optional<int64_t> last_keyframe_packet_ms = | 485 rtc::Optional<int64_t> last_keyframe_packet_ms = |
484 rtp_stream_receiver_.LastReceivedKeyframePacketMs(); | 486 rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); |
485 | 487 |
486 // To avoid spamming keyframe requests for a stream that is not active we | 488 // To avoid spamming keyframe requests for a stream that is not active we |
487 // check if we have received a packet within the last 5 seconds. | 489 // check if we have received a packet within the last 5 seconds. |
488 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; | 490 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; |
489 | 491 |
490 // If we recently (within |kMaxWaitForFrameMs|) have been receiving packets | 492 // If we recently (within |kMaxWaitForFrameMs|) have been receiving packets |
491 // belonging to a keyframe then we assume a keyframe is being received right | 493 // belonging to a keyframe then we assume a keyframe is being received right |
492 // now. | 494 // now. |
493 bool receiving_keyframe = | 495 bool receiving_keyframe = |
494 last_keyframe_packet_ms && | 496 last_keyframe_packet_ms && |
495 now_ms - *last_keyframe_packet_ms < kMaxWaitForFrameMs; | 497 now_ms - *last_keyframe_packet_ms < kMaxWaitForFrameMs; |
496 | 498 |
497 if (stream_is_active && !receiving_keyframe) { | 499 if (stream_is_active && !receiving_keyframe) { |
498 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs | 500 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs |
499 << " ms, requesting keyframe."; | 501 << " ms, requesting keyframe."; |
500 RequestKeyFrame(); | 502 RequestKeyFrame(); |
501 } | 503 } |
502 } | 504 } |
503 return true; | 505 return true; |
504 } | 506 } |
505 } // namespace internal | 507 } // namespace internal |
506 } // namespace webrtc | 508 } // namespace webrtc |
OLD | NEW |