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 |
11 #include "webrtc/video/video_receive_stream.h" | 11 #include "webrtc/video/video_receive_stream.h" |
12 | 12 |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 | 14 |
15 #include <set> | 15 #include <set> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 20 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
22 #include "webrtc/modules/utility/include/process_thread.h" | 22 #include "webrtc/modules/utility/include/process_thread.h" |
23 #include "webrtc/modules/video_coding/include/video_coding.h" | 23 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 24 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
24 #include "webrtc/system_wrappers/include/clock.h" | 25 #include "webrtc/system_wrappers/include/clock.h" |
25 #include "webrtc/video/call_stats.h" | 26 #include "webrtc/video/call_stats.h" |
26 #include "webrtc/video/receive_statistics_proxy.h" | 27 #include "webrtc/video/receive_statistics_proxy.h" |
27 #include "webrtc/video/vie_remb.h" | 28 #include "webrtc/video/vie_remb.h" |
28 #include "webrtc/video_receive_stream.h" | 29 #include "webrtc/video_receive_stream.h" |
29 | 30 |
30 namespace webrtc { | 31 namespace webrtc { |
31 | 32 |
| 33 static const bool kEnableFrameRecording = false; |
| 34 |
32 static bool UseSendSideBwe(const VideoReceiveStream::Config& config) { | 35 static bool UseSendSideBwe(const VideoReceiveStream::Config& config) { |
33 if (!config.rtp.transport_cc) | 36 if (!config.rtp.transport_cc) |
34 return false; | 37 return false; |
35 for (const auto& extension : config.rtp.extensions) { | 38 for (const auto& extension : config.rtp.extensions) { |
36 if (extension.name == RtpExtension::kTransportSequenceNumber) | 39 if (extension.name == RtpExtension::kTransportSequenceNumber) |
37 return true; | 40 return true; |
38 } | 41 } |
39 return false; | 42 return false; |
40 } | 43 } |
41 | 44 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 process_thread_(process_thread), | 159 process_thread_(process_thread), |
157 clock_(Clock::GetRealTimeClock()), | 160 clock_(Clock::GetRealTimeClock()), |
158 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 161 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
159 congestion_controller_(congestion_controller), | 162 congestion_controller_(congestion_controller), |
160 call_stats_(call_stats), | 163 call_stats_(call_stats), |
161 remb_(remb), | 164 remb_(remb), |
162 vcm_(VideoCodingModule::Create(clock_, | 165 vcm_(VideoCodingModule::Create(clock_, |
163 nullptr, | 166 nullptr, |
164 nullptr, | 167 nullptr, |
165 this, | 168 this, |
| 169 this, |
166 this)), | 170 this)), |
167 incoming_video_stream_(0, config.disable_prerenderer_smoothing), | 171 incoming_video_stream_(0, config.disable_prerenderer_smoothing), |
168 stats_proxy_(config_, clock_), | 172 stats_proxy_(config_, clock_), |
169 vie_channel_(&transport_adapter_, | 173 vie_channel_(&transport_adapter_, |
170 process_thread, | 174 process_thread, |
171 nullptr, | 175 nullptr, |
172 vcm_.get(), | 176 vcm_.get(), |
173 nullptr, | 177 nullptr, |
174 nullptr, | 178 nullptr, |
175 nullptr, | 179 nullptr, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 287 |
284 VideoCodec codec = CreateDecoderVideoCodec(decoder); | 288 VideoCodec codec = CreateDecoderVideoCodec(decoder); |
285 | 289 |
286 RTC_CHECK(vie_receiver_->SetReceiveCodec(codec)); | 290 RTC_CHECK(vie_receiver_->SetReceiveCodec(codec)); |
287 RTC_CHECK_EQ(VCM_OK, | 291 RTC_CHECK_EQ(VCM_OK, |
288 vcm_->RegisterReceiveCodec(&codec, num_cpu_cores, false)); | 292 vcm_->RegisterReceiveCodec(&codec, num_cpu_cores, false)); |
289 } | 293 } |
290 | 294 |
291 vcm_->SetRenderDelay(config.render_delay_ms); | 295 vcm_->SetRenderDelay(config.render_delay_ms); |
292 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); | 296 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); |
293 vcm_->RegisterPreDecodeImageCallback(this); | |
294 incoming_video_stream_.SetExternalCallback(this); | 297 incoming_video_stream_.SetExternalCallback(this); |
295 vie_channel_.SetIncomingVideoStream(&incoming_video_stream_); | 298 vie_channel_.SetIncomingVideoStream(&incoming_video_stream_); |
296 vie_channel_.RegisterPreRenderCallback(this); | 299 vie_channel_.RegisterPreRenderCallback(this); |
297 | 300 |
298 process_thread_->RegisterModule(vcm_.get()); | 301 process_thread_->RegisterModule(vcm_.get()); |
299 process_thread_->RegisterModule(&vie_sync_); | 302 process_thread_->RegisterModule(&vie_sync_); |
300 } | 303 } |
301 | 304 |
302 VideoReceiveStream::~VideoReceiveStream() { | 305 VideoReceiveStream::~VideoReceiveStream() { |
303 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 306 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
304 Stop(); | 307 Stop(); |
305 | 308 |
306 process_thread_->DeRegisterModule(&vie_sync_); | 309 process_thread_->DeRegisterModule(&vie_sync_); |
307 process_thread_->DeRegisterModule(vcm_.get()); | 310 process_thread_->DeRegisterModule(vcm_.get()); |
308 | 311 |
309 // Deregister external decoders so that they are no longer running during | 312 // Deregister external decoders so that they are no longer running during |
310 // destruction. This effectively stops the VCM since the decoder thread is | 313 // destruction. This effectively stops the VCM since the decoder thread is |
311 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 314 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
312 // running. | 315 // running. |
313 for (const Decoder& decoder : config_.decoders) | 316 for (const Decoder& decoder : config_.decoders) |
314 vcm_->RegisterExternalDecoder(nullptr, decoder.payload_type); | 317 vcm_->RegisterExternalDecoder(nullptr, decoder.payload_type); |
315 | 318 |
316 vie_channel_.RegisterPreRenderCallback(nullptr); | 319 vie_channel_.RegisterPreRenderCallback(nullptr); |
317 vcm_->RegisterPreDecodeImageCallback(nullptr); | |
318 | 320 |
319 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver()); | 321 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver()); |
320 rtp_rtcp_->SetREMBStatus(false); | 322 rtp_rtcp_->SetREMBStatus(false); |
321 remb_->RemoveReceiveChannel(rtp_rtcp_); | 323 remb_->RemoveReceiveChannel(rtp_rtcp_); |
322 | 324 |
323 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) | 325 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) |
324 ->RemoveStream(vie_receiver_->GetRemoteSsrc()); | 326 ->RemoveStream(vie_receiver_->GetRemoteSsrc()); |
325 } | 327 } |
326 | 328 |
327 void VideoReceiveStream::Start() { | 329 void VideoReceiveStream::Start() { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 int32_t VideoReceiveStream::Encoded( | 401 int32_t VideoReceiveStream::Encoded( |
400 const EncodedImage& encoded_image, | 402 const EncodedImage& encoded_image, |
401 const CodecSpecificInfo* codec_specific_info, | 403 const CodecSpecificInfo* codec_specific_info, |
402 const RTPFragmentationHeader* fragmentation) { | 404 const RTPFragmentationHeader* fragmentation) { |
403 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); | 405 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); |
404 if (config_.pre_decode_callback) { | 406 if (config_.pre_decode_callback) { |
405 // TODO(asapersson): Remove EncodedFrameCallbackAdapter. | 407 // TODO(asapersson): Remove EncodedFrameCallbackAdapter. |
406 encoded_frame_proxy_.Encoded( | 408 encoded_frame_proxy_.Encoded( |
407 encoded_image, codec_specific_info, fragmentation); | 409 encoded_image, codec_specific_info, fragmentation); |
408 } | 410 } |
| 411 if (kEnableFrameRecording) { |
| 412 if (!ivf_writer_.get()) { |
| 413 RTC_DCHECK(codec_specific_info); |
| 414 RtpVideoCodecTypes rtp_codec_type; |
| 415 switch (codec_specific_info->codecType) { |
| 416 case kVideoCodecVP8: |
| 417 rtp_codec_type = kRtpVideoVp8; |
| 418 break; |
| 419 case kVideoCodecVP9: |
| 420 rtp_codec_type = kRtpVideoVp9; |
| 421 break; |
| 422 case kVideoCodecH264: |
| 423 rtp_codec_type = kRtpVideoH264; |
| 424 break; |
| 425 default: |
| 426 rtp_codec_type = kRtpVideoNone; |
| 427 RTC_NOTREACHED() << "Unsupported codec " |
| 428 << codec_specific_info->codecType; |
| 429 } |
| 430 std::ostringstream oss; |
| 431 oss << "receive_bitstream_ssrc_" << config_.rtp.remote_ssrc << ".ivf"; |
| 432 ivf_writer_ = IvfFileWriter::Open(oss.str(), rtp_codec_type); |
| 433 } |
| 434 if (ivf_writer_.get()) { |
| 435 bool ok = ivf_writer_->WriteFrame(encoded_image); |
| 436 RTC_DCHECK(ok); |
| 437 } |
| 438 } |
| 439 |
409 return 0; | 440 return 0; |
410 } | 441 } |
411 | 442 |
412 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 443 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
413 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode | 444 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode |
414 : RtcpMode::kOff); | 445 : RtcpMode::kOff); |
415 } | 446 } |
416 | 447 |
417 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) { | 448 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) { |
418 static_cast<VideoReceiveStream*>(ptr)->Decode(); | 449 static_cast<VideoReceiveStream*>(ptr)->Decode(); |
419 return true; | 450 return true; |
420 } | 451 } |
421 | 452 |
422 void VideoReceiveStream::Decode() { | 453 void VideoReceiveStream::Decode() { |
423 static const int kMaxDecodeWaitTimeMs = 50; | 454 static const int kMaxDecodeWaitTimeMs = 50; |
424 vcm_->Decode(kMaxDecodeWaitTimeMs); | 455 vcm_->Decode(kMaxDecodeWaitTimeMs); |
425 } | 456 } |
426 | 457 |
427 void VideoReceiveStream::SendNack( | 458 void VideoReceiveStream::SendNack( |
428 const std::vector<uint16_t>& sequence_numbers) { | 459 const std::vector<uint16_t>& sequence_numbers) { |
429 rtp_rtcp_->SendNack(sequence_numbers); | 460 rtp_rtcp_->SendNack(sequence_numbers); |
430 } | 461 } |
431 | 462 |
432 void VideoReceiveStream::RequestKeyFrame() { | 463 void VideoReceiveStream::RequestKeyFrame() { |
433 rtp_rtcp_->RequestKeyFrame(); | 464 rtp_rtcp_->RequestKeyFrame(); |
434 } | 465 } |
435 | 466 |
436 } // namespace internal | 467 } // namespace internal |
437 } // namespace webrtc | 468 } // namespace webrtc |
OLD | NEW |