Index: webrtc/video/video_quality_test.cc |
diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc |
index b754d295485342a208420502be117e28ab1ee87e..372cd5e2e00011011c109ff0d3364a596453716d 100644 |
--- a/webrtc/video/video_quality_test.cc |
+++ b/webrtc/video/video_quality_test.cc |
@@ -28,6 +28,7 @@ |
#include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_format.h" |
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
#include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
@@ -139,6 +140,8 @@ class VideoAnalyzer : public PacketReceiver, |
uint32_t rtx_ssrc_to_analyze, |
uint32_t selected_stream_width, |
uint32_t selected_stream_height, |
+ int selected_sl, |
+ int selected_tl, |
bool is_quick_test_enabled) |
: transport_(transport), |
receiver_(nullptr), |
@@ -152,6 +155,8 @@ class VideoAnalyzer : public PacketReceiver, |
rtx_ssrc_to_analyze_(rtx_ssrc_to_analyze), |
selected_stream_width_(selected_stream_width), |
selected_stream_height_(selected_stream_height), |
+ selected_sl_(selected_sl), |
+ selected_tl_(selected_tl), |
pre_encode_proxy_(this), |
encode_timing_proxy_(this), |
frames_to_process_(duration_frames), |
@@ -162,6 +167,9 @@ class VideoAnalyzer : public PacketReceiver, |
dropped_frames_before_rendering_(0), |
last_render_time_(0), |
rtp_timestamp_delta_(0), |
+ total_media_bytes_(0), |
+ first_sending_time_(0), |
+ last_sending_time_(0), |
avg_psnr_threshold_(avg_psnr_threshold), |
avg_ssim_threshold_(avg_ssim_threshold), |
is_quick_test_enabled_(is_quick_test_enabled), |
@@ -305,11 +313,16 @@ class VideoAnalyzer : public PacketReceiver, |
int64_t timestamp = |
wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_); |
send_times_[timestamp] = current_time; |
- if (!transport_->DiscardedLastPacket() && |
- header.ssrc == ssrc_to_analyze_) { |
+ |
+ if (IsInSelectedSpatialAndTemporalLayer(packet, length, header)) { |
encoded_frame_sizes_[timestamp] += |
length - (header.headerLength + header.paddingLength); |
+ total_media_bytes_ += |
+ length - (header.headerLength + header.paddingLength); |
} |
+ if (first_sending_time_ == 0) |
+ first_sending_time_ = current_time; |
+ last_sending_time_ = current_time; |
} |
} |
return result; |
@@ -319,11 +332,7 @@ class VideoAnalyzer : public PacketReceiver, |
return transport_->SendRtcp(packet, length); |
} |
- void EncodedFrameCallback(const EncodedFrame& frame) override { |
- rtc::CritScope lock(&comparison_lock_); |
- if (frames_recorded_ < frames_to_process_) |
- encoded_frame_size_.AddSample(frame.length_); |
- } |
+ void EncodedFrameCallback(const EncodedFrame& frame) override {} |
void OnFrame(const VideoFrame& video_frame) override { |
int64_t render_time_ms = |
@@ -521,6 +530,37 @@ class VideoAnalyzer : public PacketReceiver, |
VideoAnalyzer* const parent_; |
}; |
+ bool IsInSelectedSpatialAndTemporalLayer(const uint8_t* packet, |
+ size_t length, |
+ const RTPHeader& header) { |
+ if (header.payloadType != kPayloadTypeVP9 && |
+ header.payloadType != kPayloadTypeVP8) { |
+ return true; |
+ } else { |
+ // Get VP8 and VP9 specific header to check layers indexes. |
+ const uint8_t* payload = packet + header.headerLength; |
+ const size_t payload_length = length - header.headerLength; |
+ const size_t payload_data_length = payload_length - header.paddingLength; |
+ const bool is_vp8 = header.payloadType == kPayloadTypeVP8; |
+ std::unique_ptr<RtpDepacketizer> depacketizer( |
+ RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); |
+ RtpDepacketizer::ParsedPayload parsed_payload; |
+ bool result = |
+ depacketizer->Parse(&parsed_payload, payload, payload_data_length); |
+ RTC_DCHECK(result); |
+ const int temporal_idx = static_cast<int>( |
+ is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx |
+ : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); |
+ const int spatial_idx = static_cast<int>( |
+ is_vp8 ? kNoSpatialIdx |
+ : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); |
+ return (selected_tl_ < 0 || temporal_idx == kNoTemporalIdx || |
+ temporal_idx <= selected_tl_) && |
+ (selected_sl_ < 0 || spatial_idx == kNoSpatialIdx || |
+ spatial_idx <= selected_sl_); |
+ } |
+ } |
+ |
void AddFrameComparison(const VideoFrame& reference, |
const VideoFrame& render, |
bool dropped, |
@@ -676,6 +716,9 @@ class VideoAnalyzer : public PacketReceiver, |
PrintResult("encode_usage_percent", encode_usage_percent_, " percent"); |
PrintResult("media_bitrate", media_bitrate_bps_, " bps"); |
+ printf("RESULT actual_bitrate: %s = %.6lf bps\n", test_label_.c_str(), |
+ GetAverageMediaBitrateBps()); |
+ |
if (receive_stream_ != nullptr) { |
PrintResult("decode_time", decode_time_ms_, " ms"); |
PrintResult("decode_time_max", decode_time_max_ms_, " ms"); |
@@ -800,6 +843,15 @@ class VideoAnalyzer : public PacketReceiver, |
} |
} |
+ double GetAverageMediaBitrateBps() { |
+ if (last_sending_time_ == first_sending_time_) |
+ return 0; |
sprang_webrtc
2017/02/23 10:46:54
nit: use brackets for if/else
if {
...
} else {
ilnik
2017/02/23 10:55:59
Done.
|
+ else |
+ return static_cast<double>(total_media_bytes_) * 8 / |
+ (last_sending_time_ - first_sending_time_) * |
+ rtc::kNumMillisecsPerSec; |
+ } |
+ |
// Implements VideoSinkInterface to receive captured frames from a |
// FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act |
// as a source to VideoSendStream. |
@@ -859,6 +911,8 @@ class VideoAnalyzer : public PacketReceiver, |
const uint32_t rtx_ssrc_to_analyze_; |
const uint32_t selected_stream_width_; |
const uint32_t selected_stream_height_; |
+ const int selected_sl_; |
+ const int selected_tl_; |
PreEncodeProxy pre_encode_proxy_; |
OnEncodeTimingProxy encode_timing_proxy_; |
std::vector<Sample> samples_ GUARDED_BY(comparison_lock_); |
@@ -885,6 +939,10 @@ class VideoAnalyzer : public PacketReceiver, |
int dropped_frames_before_rendering_; |
int64_t last_render_time_; |
uint32_t rtp_timestamp_delta_; |
+ int64_t total_media_bytes_; |
+ |
+ int64_t first_sending_time_; |
+ int64_t last_sending_time_; |
rtc::CriticalSection crit_; |
std::deque<VideoFrame> frames_ GUARDED_BY(crit_); |
@@ -1357,7 +1415,8 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { |
kVideoSendSsrcs[params_.ss.selected_stream], |
kSendRtxSsrcs[params_.ss.selected_stream], |
static_cast<uint32_t>(selected_stream.width), |
- static_cast<uint32_t>(selected_stream.height), is_quick_test_enabled); |
+ static_cast<uint32_t>(selected_stream.height), params.ss.selected_sl, |
+ params_.video.selected_tl, is_quick_test_enabled); |
analyzer.SetReceiver(receiver_call_->Receiver()); |
send_transport.SetReceiver(&analyzer); |
recv_transport.SetReceiver(sender_call_->Receiver()); |