 Chromium Code Reviews
 Chromium Code Reviews Issue 2974903002:
  Add rtpdump and rtc log functionality to screenshare_loopback and video_loopback  (Closed)
    
  
    Issue 2974903002:
  Add rtpdump and rtc log functionality to screenshare_loopback and video_loopback  (Closed) 
  | Index: webrtc/video/video_quality_test.cc | 
| diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc | 
| index 264c7a56bf1678f3a6f0e687ca719e2d0d605aa3..d5466aa45fcc2ef705041dd27cc71573db7204f9 100644 | 
| --- a/webrtc/video/video_quality_test.cc | 
| +++ b/webrtc/video/video_quality_test.cc | 
| @@ -49,6 +49,8 @@ | 
| #include "webrtc/test/video_renderer.h" | 
| #include "webrtc/voice_engine/include/voe_base.h" | 
| +#include "webrtc/test/rtp_file_writer.h" | 
| + | 
| namespace { | 
| constexpr int kSendStatsPollingIntervalMs = 1000; | 
| @@ -152,7 +154,8 @@ class VideoAnalyzer : public PacketReceiver, | 
| int selected_sl, | 
| int selected_tl, | 
| bool is_quick_test_enabled, | 
| - Clock* clock) | 
| + Clock* clock, | 
| + std::string rtp_dump_name) | 
| : transport_(transport), | 
| receiver_(nullptr), | 
| call_(nullptr), | 
| @@ -188,7 +191,9 @@ class VideoAnalyzer : public PacketReceiver, | 
| is_quick_test_enabled_(is_quick_test_enabled), | 
| stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), | 
| comparison_available_event_(false, false), | 
| - done_(true, false) { | 
| + done_(true, false), | 
| + clock_(clock), | 
| + start_ms_(clock->TimeInMilliseconds()) { | 
| // Create thread pool for CPU-expensive PSNR/SSIM calculations. | 
| // Try to use about as many threads as cores, but leave kMinCoresLeft alone, | 
| @@ -214,6 +219,12 @@ class VideoAnalyzer : public PacketReceiver, | 
| thread->Start(); | 
| comparison_thread_pool_.push_back(thread); | 
| } | 
| + | 
| + if (rtp_dump_name.length() > 0) { | 
| 
sprang_webrtc
2017/07/12 13:27:05
nit: if (!rtp_dump_name.empty()) ...
 
ilnik
2017/07/12 13:58:53
Done.
 | 
| + fprintf(stdout, "Writing rtp dump to %s\n", rtp_dump_name.c_str()); | 
| + rtp_file_writer_.reset(test::RtpFileWriter::Create( | 
| + test::RtpFileWriter::kRtpDump, rtp_dump_name)); | 
| + } | 
| } | 
| ~VideoAnalyzer() { | 
| @@ -266,6 +277,16 @@ class VideoAnalyzer : public PacketReceiver, | 
| if (RtpHeaderParser::IsRtcp(packet, length)) { | 
| return receiver_->DeliverPacket(media_type, packet, length, packet_time); | 
| } | 
| + | 
| + if (rtp_file_writer_) { | 
| + std::unique_ptr<test::RtpPacket> p(new test::RtpPacket()); | 
| 
sprang_webrtc
2017/07/12 13:27:05
Just stack allocate it instead.
 
ilnik
2017/07/12 13:58:52
Done.
 | 
| + memcpy(p->data, packet, length); | 
| + p->length = length; | 
| + p->original_length = length; | 
| + p->time_ms = clock_->TimeInMilliseconds() - start_ms_; | 
| + rtp_file_writer_->WritePacket(p.get()); | 
| + } | 
| + | 
| RtpUtility::RtpHeaderParser parser(packet, length); | 
| RTPHeader header; | 
| parser.Parse(&header); | 
| @@ -1059,6 +1080,10 @@ class VideoAnalyzer : public PacketReceiver, | 
| rtc::Event comparison_available_event_; | 
| std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_); | 
| rtc::Event done_; | 
| + | 
| + std::unique_ptr<test::RtpFileWriter> rtp_file_writer_; | 
| + Clock* clock_; | 
| 
sprang_webrtc
2017/07/12 13:27:05
Clock* const clock_;
 
ilnik
2017/07/12 13:58:52
Done.
 | 
| + const int64_t start_ms_; | 
| }; | 
| class Vp8EncoderFactory : public VideoEncoderFactory { | 
| @@ -1714,6 +1739,12 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { | 
| << "!"; | 
| } | 
| + bool event_log_started = false; | 
| 
sprang_webrtc
2017/07/12 13:27:05
nit: git cl format?
 
ilnik
2017/07/12 13:58:52
Done.
 | 
| + if (params.rtc_event_log_name.length() > 0) { | 
| 
sprang_webrtc
2017/07/12 13:27:05
.empty()
 
ilnik
2017/07/12 13:58:52
Done.
 | 
| + event_log_ = RtcEventLog::Create(clock_); | 
| + event_log_started = event_log_->StartLogging(params.rtc_event_log_name, -1); | 
| 
sprang_webrtc
2017/07/12 13:27:05
Why would StartLogging() fail?
Can you just DCHECK
 
ilnik
2017/07/12 13:58:52
Done.
 | 
| + } | 
| + | 
| Call::Config call_config(event_log_.get()); | 
| call_config.bitrate_config = params.call.call_bitrate_config; | 
| CreateCalls(call_config, call_config); | 
| @@ -1740,7 +1771,8 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { | 
| kVideoSendSsrcs[params_.ss.selected_stream], | 
| kSendRtxSsrcs[params_.ss.selected_stream], | 
| static_cast<size_t>(params_.ss.selected_stream), params.ss.selected_sl, | 
| - params_.video.selected_tl, is_quick_test_enabled, clock_); | 
| + params_.video.selected_tl, is_quick_test_enabled, clock_, | 
| + params_.rtp_dump_name); | 
| analyzer.SetCall(sender_call_.get()); | 
| analyzer.SetReceiver(receiver_call_->Receiver()); | 
| send_transport.SetReceiver(&analyzer); | 
| @@ -1775,7 +1807,7 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { | 
| analyzer.SetSource(video_capturer_.get(), params_.ss.infer_streams); | 
| StartEncodedFrameLogs(video_send_stream_); | 
| - StartEncodedFrameLogs(video_receive_streams_[0]); | 
| + StartEncodedFrameLogs(video_receive_streams_[params_.ss.selected_stream]); | 
| video_send_stream_->Start(); | 
| for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) | 
| thumbnail_send_stream->Start(); | 
| @@ -1818,6 +1850,9 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { | 
| DestroyStreams(); | 
| DestroyThumbnailStreams(); | 
| + if (event_log_started) { | 
| + event_log_->StopLogging(); | 
| + } | 
| if (graph_data_output_file) | 
| fclose(graph_data_output_file); | 
| } | 
| @@ -2036,7 +2071,7 @@ void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) { | 
| {rtc::CreatePlatformFile(prefix + "1.ivf"), | 
| rtc::CreatePlatformFile(prefix + "2.ivf"), | 
| rtc::CreatePlatformFile(prefix + "3.ivf")}), | 
| - 10000000); | 
| + 100000000); | 
| } | 
| } | 
| @@ -2047,7 +2082,7 @@ void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) { | 
| std::string path = | 
| params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; | 
| stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), | 
| - 10000000); | 
| + 100000000); | 
| } | 
| } | 
| } // namespace webrtc |