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 #include "webrtc/video/video_send_stream.h" | 10 #include "webrtc/video/video_send_stream.h" |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <sstream> | 13 #include <sstream> |
14 #include <string> | 14 #include <string> |
15 #include <utility> | 15 #include <utility> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/file.h" |
19 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/trace_event.h" | 21 #include "webrtc/base/trace_event.h" |
21 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 22 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
23 #include "webrtc/modules/pacing/packet_router.h" | 24 #include "webrtc/modules/pacing/packet_router.h" |
24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
25 #include "webrtc/modules/utility/include/process_thread.h" | 26 #include "webrtc/modules/utility/include/process_thread.h" |
26 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 27 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
27 #include "webrtc/video/call_stats.h" | 28 #include "webrtc/video/call_stats.h" |
28 #include "webrtc/video/vie_remb.h" | 29 #include "webrtc/video/vie_remb.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void DeRegisterProcessThread(); | 261 void DeRegisterProcessThread(); |
261 | 262 |
262 void SignalNetworkState(NetworkState state); | 263 void SignalNetworkState(NetworkState state); |
263 bool DeliverRtcp(const uint8_t* packet, size_t length); | 264 bool DeliverRtcp(const uint8_t* packet, size_t length); |
264 void Start(); | 265 void Start(); |
265 void Stop(); | 266 void Stop(); |
266 | 267 |
267 void SignalEncoderConfigurationChanged(const VideoEncoderConfig& config); | 268 void SignalEncoderConfigurationChanged(const VideoEncoderConfig& config); |
268 VideoSendStream::RtpStateMap GetRtpStates() const; | 269 VideoSendStream::RtpStateMap GetRtpStates() const; |
269 | 270 |
| 271 void SetLogFiles(rtc::PlatformFile file1 = rtc::kInvalidPlatformFileValue, |
| 272 rtc::PlatformFile file2 = rtc::kInvalidPlatformFileValue, |
| 273 rtc::PlatformFile file3 = rtc::kInvalidPlatformFileValue); |
| 274 |
270 private: | 275 private: |
271 class CheckEncoderActivityTask; | 276 class CheckEncoderActivityTask; |
272 | 277 |
273 // Implements BitrateAllocatorObserver. | 278 // Implements BitrateAllocatorObserver. |
274 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, | 279 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, |
275 uint8_t fraction_loss, | 280 uint8_t fraction_loss, |
276 int64_t rtt) override; | 281 int64_t rtt) override; |
277 | 282 |
278 // Implements webrtc::VCMProtectionCallback. | 283 // Implements webrtc::VCMProtectionCallback. |
279 int ProtectionRequest(const FecProtectionParams* delta_params, | 284 int ProtectionRequest(const FecProtectionParams* delta_params, |
(...skipping 24 matching lines...) Expand all Loading... |
304 rtc::TaskQueue* const worker_queue_; | 309 rtc::TaskQueue* const worker_queue_; |
305 | 310 |
306 rtc::CriticalSection encoder_activity_crit_sect_; | 311 rtc::CriticalSection encoder_activity_crit_sect_; |
307 CheckEncoderActivityTask* check_encoder_activity_task_ | 312 CheckEncoderActivityTask* check_encoder_activity_task_ |
308 GUARDED_BY(encoder_activity_crit_sect_); | 313 GUARDED_BY(encoder_activity_crit_sect_); |
309 CallStats* const call_stats_; | 314 CallStats* const call_stats_; |
310 CongestionController* const congestion_controller_; | 315 CongestionController* const congestion_controller_; |
311 BitrateAllocator* const bitrate_allocator_; | 316 BitrateAllocator* const bitrate_allocator_; |
312 VieRemb* const remb_; | 317 VieRemb* const remb_; |
313 | 318 |
314 static const bool kEnableFrameRecording = false; | 319 rtc::CriticalSection ivf_writers_crit_; |
315 static const int kMaxLayers = 3; | 320 static const int kMaxLayers = 3; |
316 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; | 321 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers] GUARDED_BY( |
| 322 ivf_writers_crit_); |
317 | 323 |
318 int max_padding_bitrate_; | 324 int max_padding_bitrate_; |
319 int encoder_min_bitrate_bps_; | 325 int encoder_min_bitrate_bps_; |
320 uint32_t encoder_max_bitrate_bps_; | 326 uint32_t encoder_max_bitrate_bps_; |
321 uint32_t encoder_target_rate_bps_; | 327 uint32_t encoder_target_rate_bps_; |
322 | 328 |
323 ViEEncoder* const vie_encoder_; | 329 ViEEncoder* const vie_encoder_; |
324 EncoderStateFeedback encoder_feedback_; | 330 EncoderStateFeedback encoder_feedback_; |
325 ProtectionBitrateCalculator protection_bitrate_calculator_; | 331 ProtectionBitrateCalculator protection_bitrate_calculator_; |
326 | 332 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 &state_map, std::move(send_stream_), &thread_sync_event_))); | 597 &state_map, std::move(send_stream_), &thread_sync_event_))); |
592 thread_sync_event_.Wait(rtc::Event::kForever); | 598 thread_sync_event_.Wait(rtc::Event::kForever); |
593 return state_map; | 599 return state_map; |
594 } | 600 } |
595 | 601 |
596 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 602 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
597 // Called on a network thread. | 603 // Called on a network thread. |
598 return send_stream_->DeliverRtcp(packet, length); | 604 return send_stream_->DeliverRtcp(packet, length); |
599 } | 605 } |
600 | 606 |
| 607 void VideoSendStream::SetLogFiles(rtc::PlatformFile file1, |
| 608 rtc::PlatformFile file2, |
| 609 rtc::PlatformFile file3) { |
| 610 send_stream_->SetLogFiles(file1, file2, file3); |
| 611 } |
| 612 |
601 VideoSendStreamImpl::VideoSendStreamImpl( | 613 VideoSendStreamImpl::VideoSendStreamImpl( |
602 SendStatisticsProxy* stats_proxy, | 614 SendStatisticsProxy* stats_proxy, |
603 rtc::TaskQueue* worker_queue, | 615 rtc::TaskQueue* worker_queue, |
604 CallStats* call_stats, | 616 CallStats* call_stats, |
605 CongestionController* congestion_controller, | 617 CongestionController* congestion_controller, |
606 BitrateAllocator* bitrate_allocator, | 618 BitrateAllocator* bitrate_allocator, |
607 SendDelayStats* send_delay_stats, | 619 SendDelayStats* send_delay_stats, |
608 VieRemb* remb, | 620 VieRemb* remb, |
609 ViEEncoder* vie_encoder, | 621 ViEEncoder* vie_encoder, |
610 RtcEventLog* event_log, | 622 RtcEventLog* event_log, |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 { | 869 { |
858 rtc::CritScope lock(&encoder_activity_crit_sect_); | 870 rtc::CritScope lock(&encoder_activity_crit_sect_); |
859 if (check_encoder_activity_task_) | 871 if (check_encoder_activity_task_) |
860 check_encoder_activity_task_->UpdateEncoderActivity(); | 872 check_encoder_activity_task_->UpdateEncoderActivity(); |
861 } | 873 } |
862 | 874 |
863 protection_bitrate_calculator_.UpdateWithEncodedData(encoded_image); | 875 protection_bitrate_calculator_.UpdateWithEncodedData(encoded_image); |
864 EncodedImageCallback::Result result = payload_router_.OnEncodedImage( | 876 EncodedImageCallback::Result result = payload_router_.OnEncodedImage( |
865 encoded_image, codec_specific_info, fragmentation); | 877 encoded_image, codec_specific_info, fragmentation); |
866 | 878 |
867 if (kEnableFrameRecording) { | 879 RTC_DCHECK(codec_specific_info); |
868 int layer = codec_specific_info->codecType == kVideoCodecVP8 | 880 |
869 ? codec_specific_info->codecSpecific.VP8.simulcastIdx | 881 int layer = codec_specific_info->codecType == kVideoCodecVP8 |
870 : 0; | 882 ? codec_specific_info->codecSpecific.VP8.simulcastIdx |
871 IvfFileWriter* file_writer; | 883 : 0; |
872 { | 884 { |
873 if (file_writers_[layer] == nullptr) { | 885 rtc::CritScope lock(&ivf_writers_crit_); |
874 std::ostringstream oss; | 886 if (file_writers_[layer].get()) { |
875 oss << "send_bitstream_ssrc"; | 887 bool ok = file_writers_[layer]->WriteFrame( |
876 for (uint32_t ssrc : config_->rtp.ssrcs) | 888 encoded_image, codec_specific_info->codecType); |
877 oss << "_" << ssrc; | |
878 oss << "_layer" << layer << ".ivf"; | |
879 file_writers_[layer] = | |
880 IvfFileWriter::Open(oss.str(), codec_specific_info->codecType); | |
881 } | |
882 file_writer = file_writers_[layer].get(); | |
883 } | |
884 if (file_writer) { | |
885 bool ok = file_writer->WriteFrame(encoded_image); | |
886 RTC_DCHECK(ok); | 889 RTC_DCHECK(ok); |
887 } | 890 } |
888 } | 891 } |
889 | 892 |
890 return result; | 893 return result; |
891 } | 894 } |
892 | 895 |
893 void VideoSendStreamImpl::ConfigureProtection() { | 896 void VideoSendStreamImpl::ConfigureProtection() { |
894 RTC_DCHECK_RUN_ON(worker_queue_); | 897 RTC_DCHECK_RUN_ON(worker_queue_); |
895 // Enable NACK, FEC or both. | 898 // Enable NACK, FEC or both. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); | 1033 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); |
1031 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; | 1034 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; |
1032 | 1035 |
1033 encoder_target_rate_bps_ = | 1036 encoder_target_rate_bps_ = |
1034 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1037 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); |
1035 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); | 1038 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); |
1036 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); | 1039 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); |
1037 return protection_bitrate; | 1040 return protection_bitrate; |
1038 } | 1041 } |
1039 | 1042 |
| 1043 void VideoSendStreamImpl::SetLogFiles(rtc::PlatformFile file1, |
| 1044 rtc::PlatformFile file2, |
| 1045 rtc::PlatformFile file3) { |
| 1046 { |
| 1047 rtc::CritScope lock(&ivf_writers_crit_); |
| 1048 if (file1 == rtc::kInvalidPlatformFileValue) { |
| 1049 file_writers_[0].reset(); |
| 1050 } else { |
| 1051 file_writers_[0] = IvfFileWriter::Wrap(rtc::File(file1)); |
| 1052 } |
| 1053 |
| 1054 if (file2 == rtc::kInvalidPlatformFileValue) { |
| 1055 file_writers_[1].reset(); |
| 1056 } else { |
| 1057 file_writers_[1] = IvfFileWriter::Wrap(rtc::File(file2)); |
| 1058 } |
| 1059 |
| 1060 if (file3 == rtc::kInvalidPlatformFileValue) { |
| 1061 file_writers_[2].reset(); |
| 1062 } else { |
| 1063 file_writers_[2] = IvfFileWriter::Wrap(rtc::File(file3)); |
| 1064 } |
| 1065 } |
| 1066 |
| 1067 if (file1 != rtc::kInvalidPlatformFileValue || |
| 1068 file2 != rtc::kInvalidPlatformFileValue || |
| 1069 file3 != rtc::kInvalidPlatformFileValue) { |
| 1070 vie_encoder_->SendKeyFrame(); |
| 1071 } |
| 1072 } |
| 1073 |
1040 int VideoSendStreamImpl::ProtectionRequest( | 1074 int VideoSendStreamImpl::ProtectionRequest( |
1041 const FecProtectionParams* delta_params, | 1075 const FecProtectionParams* delta_params, |
1042 const FecProtectionParams* key_params, | 1076 const FecProtectionParams* key_params, |
1043 uint32_t* sent_video_rate_bps, | 1077 uint32_t* sent_video_rate_bps, |
1044 uint32_t* sent_nack_rate_bps, | 1078 uint32_t* sent_nack_rate_bps, |
1045 uint32_t* sent_fec_rate_bps) { | 1079 uint32_t* sent_fec_rate_bps) { |
1046 RTC_DCHECK_RUN_ON(worker_queue_); | 1080 RTC_DCHECK_RUN_ON(worker_queue_); |
1047 *sent_video_rate_bps = 0; | 1081 *sent_video_rate_bps = 0; |
1048 *sent_nack_rate_bps = 0; | 1082 *sent_nack_rate_bps = 0; |
1049 *sent_fec_rate_bps = 0; | 1083 *sent_fec_rate_bps = 0; |
1050 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1084 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1051 uint32_t not_used = 0; | 1085 uint32_t not_used = 0; |
1052 uint32_t module_video_rate = 0; | 1086 uint32_t module_video_rate = 0; |
1053 uint32_t module_fec_rate = 0; | 1087 uint32_t module_fec_rate = 0; |
1054 uint32_t module_nack_rate = 0; | 1088 uint32_t module_nack_rate = 0; |
1055 rtp_rtcp->SetFecParameters(delta_params, key_params); | 1089 rtp_rtcp->SetFecParameters(delta_params, key_params); |
1056 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, | 1090 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, |
1057 &module_nack_rate); | 1091 &module_nack_rate); |
1058 *sent_video_rate_bps += module_video_rate; | 1092 *sent_video_rate_bps += module_video_rate; |
1059 *sent_nack_rate_bps += module_nack_rate; | 1093 *sent_nack_rate_bps += module_nack_rate; |
1060 *sent_fec_rate_bps += module_fec_rate; | 1094 *sent_fec_rate_bps += module_fec_rate; |
1061 } | 1095 } |
1062 return 0; | 1096 return 0; |
1063 } | 1097 } |
1064 | 1098 |
1065 } // namespace internal | 1099 } // namespace internal |
1066 } // namespace webrtc | 1100 } // namespace webrtc |
OLD | NEW |