Index: webrtc/video/full_stack.cc |
diff --git a/webrtc/video/full_stack.cc b/webrtc/video/full_stack.cc |
index 1220482a1dbf597f44c9fac31bf997852a06c735..cdd6395da1b10f59c8ae6a9459c95cdbe0177ba2 100644 |
--- a/webrtc/video/full_stack.cc |
+++ b/webrtc/video/full_stack.cc |
@@ -14,6 +14,7 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "webrtc/base/format_macros.h" |
#include "webrtc/base/scoped_ptr.h" |
#include "webrtc/base/thread_annotations.h" |
#include "webrtc/call.h" |
@@ -25,8 +26,6 @@ |
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
#include "webrtc/system_wrappers/interface/event_wrapper.h" |
#include "webrtc/system_wrappers/interface/sleep.h" |
-#include "webrtc/test/call_test.h" |
-#include "webrtc/test/direct_transport.h" |
#include "webrtc/test/encoder_settings.h" |
#include "webrtc/test/fake_encoder.h" |
#include "webrtc/test/frame_generator.h" |
@@ -34,35 +33,13 @@ |
#include "webrtc/test/statistics.h" |
#include "webrtc/test/testsupport/fileutils.h" |
#include "webrtc/typedefs.h" |
+#include "webrtc/video/full_stack.h" |
namespace webrtc { |
static const int kFullStackTestDurationSecs = 60; |
static const int kSendStatsPollingIntervalMs = 1000; |
-struct FullStackTestParams { |
- const char* test_label; |
- struct { |
- const char* name; |
- size_t width, height; |
- int fps; |
- } clip; |
- bool screenshare; |
- int min_bitrate_bps; |
- int target_bitrate_bps; |
- int max_bitrate_bps; |
- double avg_psnr_threshold; |
- double avg_ssim_threshold; |
- int test_durations_secs; |
- std::string codec; |
- FakeNetworkPipe::Config link; |
-}; |
- |
-class FullStackTest : public test::CallTest { |
- protected: |
- void RunTest(const FullStackTestParams& params); |
-}; |
- |
class VideoAnalyzer : public PacketReceiver, |
public newapi::Transport, |
public VideoRenderer, |
@@ -74,12 +51,14 @@ class VideoAnalyzer : public PacketReceiver, |
const char* test_label, |
double avg_psnr_threshold, |
double avg_ssim_threshold, |
- int duration_frames) |
+ int duration_frames, |
+ const std::string& stats_output_filename) |
: input_(input), |
transport_(transport), |
receiver_(nullptr), |
send_stream_(nullptr), |
test_label_(test_label), |
+ stats_output_filename_(stats_output_filename), |
frames_to_process_(duration_frames), |
frames_recorded_(0), |
frames_processed_(0), |
@@ -171,8 +150,11 @@ class VideoAnalyzer : public PacketReceiver, |
header.timestamp - first_send_frame_.timestamp(); |
first_send_frame_.Reset(); |
} |
- send_times_[header.timestamp - rtp_timestamp_delta_] = |
+ uint32_t timestamp = header.timestamp - rtp_timestamp_delta_; |
+ send_times_[timestamp] = |
Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
+ encoded_frame_sizes_[timestamp] += |
+ length - (header.headerLength + header.paddingLength); |
sprang_webrtc
2015/09/03 08:59:39
Do we ever use simulcast in these tests? Then this
ivica
2015/09/03 09:30:34
Simulcast is not supported here yet. That will be
sprang_webrtc
2015/09/03 11:53:22
Acknowledged.
|
} |
return transport_->SendRtp(packet, length); |
@@ -184,8 +166,9 @@ class VideoAnalyzer : public PacketReceiver, |
void EncodedFrameCallback(const EncodedFrame& frame) override { |
rtc::CritScope lock(&comparison_lock_); |
- if (frames_recorded_ < frames_to_process_) |
+ if (frames_recorded_ < frames_to_process_) { |
encoded_frame_size_.AddSample(frame.length_); |
+ } |
sprang_webrtc
2015/09/03 08:59:39
Don't think you need these extra {}
ivica
2015/09/03 09:30:34
Done.
|
} |
void RenderFrame(const VideoFrame& video_frame, |
@@ -253,20 +236,26 @@ class VideoAnalyzer : public PacketReceiver, |
private: |
struct FrameComparison { |
FrameComparison() |
- : dropped(false), send_time_ms(0), recv_time_ms(0), render_time_ms(0) {} |
+ : dropped(false), |
+ send_time_ms(0), |
+ recv_time_ms(0), |
+ render_time_ms(0), |
+ encoded_frame_size(0) {} |
FrameComparison(const VideoFrame& reference, |
const VideoFrame& render, |
bool dropped, |
int64_t send_time_ms, |
int64_t recv_time_ms, |
- int64_t render_time_ms) |
+ int64_t render_time_ms, |
+ size_t encoded_frame_size) |
: reference(reference), |
render(render), |
dropped(dropped), |
send_time_ms(send_time_ms), |
recv_time_ms(recv_time_ms), |
- render_time_ms(render_time_ms) {} |
+ render_time_ms(render_time_ms), |
+ encoded_frame_size(encoded_frame_size) {} |
VideoFrame reference; |
VideoFrame render; |
@@ -274,6 +263,35 @@ class VideoAnalyzer : public PacketReceiver, |
int64_t send_time_ms; |
int64_t recv_time_ms; |
int64_t render_time_ms; |
+ size_t encoded_frame_size; |
+ }; |
+ |
+ struct Sample { |
+ Sample(double dropped, |
+ double input_time_ms, |
+ double send_time_ms, |
+ double recv_time_ms, |
+ double encoded_frame_size, |
+ double psnr, |
+ double ssim, |
+ double decoded_time_ms) |
+ : dropped(dropped), |
+ input_time_ms(input_time_ms), |
+ send_time_ms(send_time_ms), |
+ recv_time_ms(recv_time_ms), |
+ encoded_frame_size(encoded_frame_size), |
+ psnr(psnr), |
+ ssim(ssim), |
+ decoded_time_ms(decoded_time_ms) {} |
+ |
+ double dropped; |
+ double input_time_ms; |
+ double send_time_ms; |
+ double recv_time_ms; |
+ double encoded_frame_size; |
+ double psnr; |
+ double ssim; |
+ double decoded_time_ms; |
}; |
void AddFrameComparison(const VideoFrame& reference, |
@@ -286,10 +304,18 @@ class VideoAnalyzer : public PacketReceiver, |
int64_t recv_time_ms = recv_times_[reference.timestamp()]; |
recv_times_.erase(reference.timestamp()); |
+ size_t encoded_size = encoded_frame_sizes_[reference.timestamp()]; |
+ encoded_frame_sizes_.erase(reference.timestamp()); |
+ |
+ VideoFrame reference_copy; |
+ VideoFrame render_copy; |
+ reference_copy.CopyFrame(reference); |
+ render_copy.CopyFrame(render); |
+ |
rtc::CritScope crit(&comparison_lock_); |
- comparisons_.push_back(FrameComparison(reference, render, dropped, |
+ comparisons_.push_back(FrameComparison(reference_copy, render_copy, dropped, |
send_time_ms, recv_time_ms, |
- render_time_ms)); |
+ render_time_ms, encoded_size)); |
comparison_available_event_->Set(); |
} |
@@ -347,6 +373,8 @@ class VideoAnalyzer : public PacketReceiver, |
if (FrameProcessed()) { |
PrintResults(); |
+ if (!stats_output_filename_.empty()) |
+ PrintSamplesToFile(); |
done_->Set(); |
comparison_available_event_->Set(); |
return false; |
@@ -419,9 +447,18 @@ class VideoAnalyzer : public PacketReceiver, |
double psnr = I420PSNR(&comparison.reference, &comparison.render); |
double ssim = I420SSIM(&comparison.reference, &comparison.render); |
+ int64_t input_time_ms = comparison.reference.ntp_time_ms(); |
+ Sample sample(comparison.dropped, input_time_ms, comparison.send_time_ms, |
+ comparison.recv_time_ms, comparison.encoded_frame_size, psnr, |
+ ssim, |
+ comparison.render_time_ms); // decoded_time_ms |
sprang_webrtc
2015/09/03 08:59:39
Why use a temporary?
ivica
2015/09/03 09:30:34
Done.
|
+ |
rtc::CritScope crit(&comparison_lock_); |
+ if (!stats_output_filename_.empty()) |
+ samples_.push_back(sample); |
psnr_.AddSample(psnr); |
ssim_.AddSample(ssim); |
+ |
if (comparison.dropped) { |
++dropped_frames_; |
return; |
@@ -430,11 +467,11 @@ class VideoAnalyzer : public PacketReceiver, |
rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_); |
last_render_time_ = comparison.render_time_ms; |
- int64_t input_time_ms = comparison.reference.ntp_time_ms(); |
sender_time_.AddSample(comparison.send_time_ms - input_time_ms); |
receiver_time_.AddSample(comparison.render_time_ms - |
comparison.recv_time_ms); |
end_to_end_.AddSample(comparison.render_time_ms - input_time_ms); |
+ encoded_frame_size_.AddSample(comparison.encoded_frame_size); |
} |
void PrintResult(const char* result_type, |
@@ -448,7 +485,42 @@ class VideoAnalyzer : public PacketReceiver, |
unit); |
} |
+ void PrintSamplesToFile(void) { |
+ FILE* f = fopen(stats_output_filename_.c_str(), "w"); |
+ if (f == NULL) { |
+ fprintf(stderr, "Couldn't open file %s\n", |
+ stats_output_filename_.c_str()); |
+ abort(); |
+ } |
+ |
+ rtc::CritScope crit(&comparison_lock_); |
+ std::sort(samples_.begin(), samples_.end(), |
+ [](const Sample& A, const Sample& B) |
+ -> bool { return A.input_time_ms < B.input_time_ms; }); |
+ |
+ fprintf(f, "%s\n", test_label_); |
+ fprintf(f, "%" PRIuS "\n", samples_.size()); |
+ fprintf(f, |
+ "dropped " |
+ "input_time_ms " |
+ "send_time_ms " |
+ "recv_time_ms " |
+ "encoded_frame_size " |
+ "psnr " |
+ "ssim " |
+ "decoded_time_ms\n"); |
+ for (Sample& sample : samples_) { |
sprang_webrtc
2015/09/03 08:59:39
const Sample&
ivica
2015/09/03 09:30:34
Done.
|
+ fprintf(f, "%lf %lf %lf %lf %lf %lf %lf %lf\n", sample.dropped, |
+ sample.input_time_ms, sample.send_time_ms, sample.recv_time_ms, |
+ sample.encoded_frame_size, sample.psnr, sample.ssim, |
+ sample.decoded_time_ms); |
+ } |
+ fclose(f); |
+ } |
+ |
const char* const test_label_; |
+ std::string stats_output_filename_; |
+ std::vector<Sample> samples_ GUARDED_BY(comparison_lock_); |
test::Statistics sender_time_ GUARDED_BY(comparison_lock_); |
test::Statistics receiver_time_ GUARDED_BY(comparison_lock_); |
test::Statistics psnr_ GUARDED_BY(comparison_lock_); |
@@ -470,9 +542,11 @@ class VideoAnalyzer : public PacketReceiver, |
rtc::CriticalSection crit_; |
std::deque<VideoFrame> frames_ GUARDED_BY(crit_); |
+ std::deque<VideoSendStream::Stats> send_stats_ GUARDED_BY(crit_); |
VideoFrame last_rendered_frame_ GUARDED_BY(crit_); |
std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_); |
std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_); |
+ std::map<uint32_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); |
VideoFrame first_send_frame_ GUARDED_BY(crit_); |
const double avg_psnr_threshold_; |
const double avg_ssim_threshold_; |
@@ -486,11 +560,16 @@ class VideoAnalyzer : public PacketReceiver, |
}; |
void FullStackTest::RunTest(const FullStackTestParams& params) { |
+ // TODO(ivica): Add num_temporal_layers as a param. |
+ unsigned char num_temporal_layers = |
+ params.stats_output_filename.empty() ? 2 : 1; |
+ |
test::DirectTransport send_transport(params.link); |
test::DirectTransport recv_transport(params.link); |
VideoAnalyzer analyzer(nullptr, &send_transport, params.test_label, |
params.avg_psnr_threshold, params.avg_ssim_threshold, |
- params.test_durations_secs * params.clip.fps); |
+ params.test_durations_secs * params.clip.fps, |
+ params.stats_output_filename); |
CreateCalls(Call::Config(&analyzer), Call::Config(&recv_transport)); |
@@ -538,18 +617,21 @@ void FullStackTest::RunTest(const FullStackTestParams& params) { |
vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
vp8_settings.denoisingOn = false; |
vp8_settings.frameDroppingOn = false; |
- vp8_settings.numberOfTemporalLayers = 2; |
+ vp8_settings.numberOfTemporalLayers = num_temporal_layers; |
encoder_config_.encoder_specific_settings = &vp8_settings; |
} else if (params.codec == "VP9") { |
vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
vp9_settings.denoisingOn = false; |
vp9_settings.frameDroppingOn = false; |
- vp9_settings.numberOfTemporalLayers = 2; |
+ vp9_settings.numberOfTemporalLayers = num_temporal_layers; |
encoder_config_.encoder_specific_settings = &vp9_settings; |
} |
stream->temporal_layer_thresholds_bps.clear(); |
- stream->temporal_layer_thresholds_bps.push_back(stream->target_bitrate_bps); |
+ if (num_temporal_layers > 1) { |
+ stream->temporal_layer_thresholds_bps.push_back( |
+ stream->target_bitrate_bps); |
+ } |
} |
CreateMatchingReceiveConfigs(); |