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