Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: webrtc/video/video_send_stream.cc

Issue 2303273002: Expose Ivf logging through the native API (Closed)
Patch Set: Nit Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video_receive_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common_types.h"
18 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/base/file.h"
19 #include "webrtc/base/logging.h" 21 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 22 #include "webrtc/base/trace_event.h"
21 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" 24 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
23 #include "webrtc/modules/pacing/packet_router.h" 25 #include "webrtc/modules/pacing/packet_router.h"
24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
25 #include "webrtc/modules/utility/include/process_thread.h" 27 #include "webrtc/modules/utility/include/process_thread.h"
26 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" 28 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h"
27 #include "webrtc/video/call_stats.h" 29 #include "webrtc/video/call_stats.h"
28 #include "webrtc/video/vie_remb.h" 30 #include "webrtc/video/vie_remb.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 void RegisterProcessThread(ProcessThread* module_process_thread); 262 void RegisterProcessThread(ProcessThread* module_process_thread);
261 void DeRegisterProcessThread(); 263 void DeRegisterProcessThread();
262 264
263 void SignalNetworkState(NetworkState state); 265 void SignalNetworkState(NetworkState state);
264 bool DeliverRtcp(const uint8_t* packet, size_t length); 266 bool DeliverRtcp(const uint8_t* packet, size_t length);
265 void Start(); 267 void Start();
266 void Stop(); 268 void Stop();
267 269
268 VideoSendStream::RtpStateMap GetRtpStates() const; 270 VideoSendStream::RtpStateMap GetRtpStates() const;
269 271
272 void EnableEncodedFrameRecording(const std::vector<rtc::PlatformFile>& files,
273 size_t byte_limit);
274
270 private: 275 private:
271 class CheckEncoderActivityTask; 276 class CheckEncoderActivityTask;
272 class EncoderReconfiguredTask; 277 class EncoderReconfiguredTask;
273 278
274 // Implements BitrateAllocatorObserver. 279 // Implements BitrateAllocatorObserver.
275 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, 280 uint32_t OnBitrateUpdated(uint32_t bitrate_bps,
276 uint8_t fraction_loss, 281 uint8_t fraction_loss,
277 int64_t rtt) override; 282 int64_t rtt) override;
278 283
279 // Implements webrtc::VCMProtectionCallback. 284 // Implements webrtc::VCMProtectionCallback.
(...skipping 29 matching lines...) Expand all
309 314
310 rtc::CriticalSection encoder_activity_crit_sect_; 315 rtc::CriticalSection encoder_activity_crit_sect_;
311 CheckEncoderActivityTask* check_encoder_activity_task_ 316 CheckEncoderActivityTask* check_encoder_activity_task_
312 GUARDED_BY(encoder_activity_crit_sect_); 317 GUARDED_BY(encoder_activity_crit_sect_);
313 318
314 CallStats* const call_stats_; 319 CallStats* const call_stats_;
315 CongestionController* const congestion_controller_; 320 CongestionController* const congestion_controller_;
316 BitrateAllocator* const bitrate_allocator_; 321 BitrateAllocator* const bitrate_allocator_;
317 VieRemb* const remb_; 322 VieRemb* const remb_;
318 323
319 static const bool kEnableFrameRecording = false; 324 rtc::CriticalSection ivf_writers_crit_;
320 static const int kMaxLayers = 3; 325 std::unique_ptr<IvfFileWriter> file_writers_[kMaxSimulcastStreams] GUARDED_BY(
321 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; 326 ivf_writers_crit_);
322 327
323 int max_padding_bitrate_; 328 int max_padding_bitrate_;
324 int encoder_min_bitrate_bps_; 329 int encoder_min_bitrate_bps_;
325 uint32_t encoder_max_bitrate_bps_; 330 uint32_t encoder_max_bitrate_bps_;
326 uint32_t encoder_target_rate_bps_; 331 uint32_t encoder_target_rate_bps_;
327 332
328 ViEEncoder* const vie_encoder_; 333 ViEEncoder* const vie_encoder_;
329 EncoderStateFeedback encoder_feedback_; 334 EncoderStateFeedback encoder_feedback_;
330 ProtectionBitrateCalculator protection_bitrate_calculator_; 335 ProtectionBitrateCalculator protection_bitrate_calculator_;
331 336
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 &state_map, std::move(send_stream_), &thread_sync_event_))); 613 &state_map, std::move(send_stream_), &thread_sync_event_)));
609 thread_sync_event_.Wait(rtc::Event::kForever); 614 thread_sync_event_.Wait(rtc::Event::kForever);
610 return state_map; 615 return state_map;
611 } 616 }
612 617
613 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { 618 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
614 // Called on a network thread. 619 // Called on a network thread.
615 return send_stream_->DeliverRtcp(packet, length); 620 return send_stream_->DeliverRtcp(packet, length);
616 } 621 }
617 622
623 void VideoSendStream::EnableEncodedFrameRecording(
624 const std::vector<rtc::PlatformFile>& files,
625 size_t byte_limit) {
626 send_stream_->EnableEncodedFrameRecording(files, byte_limit);
627 }
628
618 VideoSendStreamImpl::VideoSendStreamImpl( 629 VideoSendStreamImpl::VideoSendStreamImpl(
619 SendStatisticsProxy* stats_proxy, 630 SendStatisticsProxy* stats_proxy,
620 rtc::TaskQueue* worker_queue, 631 rtc::TaskQueue* worker_queue,
621 CallStats* call_stats, 632 CallStats* call_stats,
622 CongestionController* congestion_controller, 633 CongestionController* congestion_controller,
623 BitrateAllocator* bitrate_allocator, 634 BitrateAllocator* bitrate_allocator,
624 SendDelayStats* send_delay_stats, 635 SendDelayStats* send_delay_stats,
625 VieRemb* remb, 636 VieRemb* remb,
626 ViEEncoder* vie_encoder, 637 ViEEncoder* vie_encoder,
627 RtcEventLog* event_log, 638 RtcEventLog* event_log,
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 { 895 {
885 rtc::CritScope lock(&encoder_activity_crit_sect_); 896 rtc::CritScope lock(&encoder_activity_crit_sect_);
886 if (check_encoder_activity_task_) 897 if (check_encoder_activity_task_)
887 check_encoder_activity_task_->UpdateEncoderActivity(); 898 check_encoder_activity_task_->UpdateEncoderActivity();
888 } 899 }
889 900
890 protection_bitrate_calculator_.UpdateWithEncodedData(encoded_image); 901 protection_bitrate_calculator_.UpdateWithEncodedData(encoded_image);
891 EncodedImageCallback::Result result = payload_router_.OnEncodedImage( 902 EncodedImageCallback::Result result = payload_router_.OnEncodedImage(
892 encoded_image, codec_specific_info, fragmentation); 903 encoded_image, codec_specific_info, fragmentation);
893 904
894 if (kEnableFrameRecording) { 905 RTC_DCHECK(codec_specific_info);
895 int layer = codec_specific_info->codecType == kVideoCodecVP8 906
896 ? codec_specific_info->codecSpecific.VP8.simulcastIdx 907 int layer = codec_specific_info->codecType == kVideoCodecVP8
897 : 0; 908 ? codec_specific_info->codecSpecific.VP8.simulcastIdx
898 IvfFileWriter* file_writer; 909 : 0;
899 { 910 {
900 if (file_writers_[layer] == nullptr) { 911 rtc::CritScope lock(&ivf_writers_crit_);
901 std::ostringstream oss; 912 if (file_writers_[layer].get()) {
902 oss << "send_bitstream_ssrc"; 913 bool ok = file_writers_[layer]->WriteFrame(
903 for (uint32_t ssrc : config_->rtp.ssrcs) 914 encoded_image, codec_specific_info->codecType);
904 oss << "_" << ssrc;
905 oss << "_layer" << layer << ".ivf";
906 file_writers_[layer] =
907 IvfFileWriter::Open(oss.str(), codec_specific_info->codecType);
908 }
909 file_writer = file_writers_[layer].get();
910 }
911 if (file_writer) {
912 bool ok = file_writer->WriteFrame(encoded_image);
913 RTC_DCHECK(ok); 915 RTC_DCHECK(ok);
914 } 916 }
915 } 917 }
916 918
917 return result; 919 return result;
918 } 920 }
919 921
920 void VideoSendStreamImpl::ConfigureProtection() { 922 void VideoSendStreamImpl::ConfigureProtection() {
921 RTC_DCHECK_RUN_ON(worker_queue_); 923 RTC_DCHECK_RUN_ON(worker_queue_);
922 // Enable NACK, FEC or both. 924 // Enable NACK, FEC or both.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); 1059 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt);
1058 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; 1060 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_;
1059 1061
1060 encoder_target_rate_bps_ = 1062 encoder_target_rate_bps_ =
1061 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); 1063 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_);
1062 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); 1064 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt);
1063 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); 1065 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_);
1064 return protection_bitrate; 1066 return protection_bitrate;
1065 } 1067 }
1066 1068
1069 void VideoSendStreamImpl::EnableEncodedFrameRecording(
1070 const std::vector<rtc::PlatformFile>& files,
1071 size_t byte_limit) {
1072 {
1073 rtc::CritScope lock(&ivf_writers_crit_);
1074 for (unsigned int i = 0; i < kMaxSimulcastStreams; ++i) {
1075 if (i < files.size()) {
1076 file_writers_[i] = IvfFileWriter::Wrap(rtc::File(files[i]), byte_limit);
1077 } else {
1078 file_writers_[i].reset();
1079 }
1080 }
1081 }
1082
1083 if (!files.empty()) {
1084 // Make a keyframe appear as early as possible in the logs, to give actually
1085 // decodable output.
1086 vie_encoder_->SendKeyFrame();
1087 }
1088 }
1089
1067 int VideoSendStreamImpl::ProtectionRequest( 1090 int VideoSendStreamImpl::ProtectionRequest(
1068 const FecProtectionParams* delta_params, 1091 const FecProtectionParams* delta_params,
1069 const FecProtectionParams* key_params, 1092 const FecProtectionParams* key_params,
1070 uint32_t* sent_video_rate_bps, 1093 uint32_t* sent_video_rate_bps,
1071 uint32_t* sent_nack_rate_bps, 1094 uint32_t* sent_nack_rate_bps,
1072 uint32_t* sent_fec_rate_bps) { 1095 uint32_t* sent_fec_rate_bps) {
1073 RTC_DCHECK_RUN_ON(worker_queue_); 1096 RTC_DCHECK_RUN_ON(worker_queue_);
1074 *sent_video_rate_bps = 0; 1097 *sent_video_rate_bps = 0;
1075 *sent_nack_rate_bps = 0; 1098 *sent_nack_rate_bps = 0;
1076 *sent_fec_rate_bps = 0; 1099 *sent_fec_rate_bps = 0;
1077 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { 1100 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
1078 uint32_t not_used = 0; 1101 uint32_t not_used = 0;
1079 uint32_t module_video_rate = 0; 1102 uint32_t module_video_rate = 0;
1080 uint32_t module_fec_rate = 0; 1103 uint32_t module_fec_rate = 0;
1081 uint32_t module_nack_rate = 0; 1104 uint32_t module_nack_rate = 0;
1082 rtp_rtcp->SetFecParameters(delta_params, key_params); 1105 rtp_rtcp->SetFecParameters(delta_params, key_params);
1083 rtp_rtcp->BitrateSent(&not_used, &module_video_rate, &module_fec_rate, 1106 rtp_rtcp->BitrateSent(&not_used, &module_video_rate, &module_fec_rate,
1084 &module_nack_rate); 1107 &module_nack_rate);
1085 *sent_video_rate_bps += module_video_rate; 1108 *sent_video_rate_bps += module_video_rate;
1086 *sent_nack_rate_bps += module_nack_rate; 1109 *sent_nack_rate_bps += module_nack_rate;
1087 *sent_fec_rate_bps += module_fec_rate; 1110 *sent_fec_rate_bps += module_fec_rate;
1088 } 1111 }
1089 return 0; 1112 return 0;
1090 } 1113 }
1091 1114
1092 } // namespace internal 1115 } // namespace internal
1093 } // namespace webrtc 1116 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video_receive_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698