diff --git a/talk/media/base/videocapturer.cc b/talk/media/base/videocapturer.cc index 877c410305..59860a40ce 100644 --- a/talk/media/base/videocapturer.cc +++ b/talk/media/base/videocapturer.cc @@ -326,11 +326,13 @@ std::string VideoCapturer::ToString(const CapturedFrame* captured_frame) const { void VideoCapturer::GetStats(VariableInfo* adapt_drops_stats, VariableInfo* effect_drops_stats, - VariableInfo* frame_time_stats) { + VariableInfo* frame_time_stats, + VideoFormat* last_captured_frame_format) { talk_base::CritScope cs(&frame_stats_crit_); GetVariableSnapshot(adapt_frame_drops_data_, adapt_drops_stats); GetVariableSnapshot(effect_frame_drops_data_, effect_drops_stats); GetVariableSnapshot(frame_time_data_, frame_time_stats); + *last_captured_frame_format = last_captured_frame_format_; adapt_frame_drops_data_.Reset(); effect_frame_drops_data_.Reset(); @@ -530,18 +532,7 @@ void VideoCapturer::OnFrameCaptured(VideoCapturer*, } SignalVideoFrame(this, adapted_frame); - double time_now = frame_length_time_reporter_.TimerNow(); - if (previous_frame_time_ != 0.0) { - // Update stats protected from jmi data fetches. - talk_base::CritScope cs(&frame_stats_crit_); - - adapt_frame_drops_data_.AddSample(adapt_frame_drops_); - effect_frame_drops_data_.AddSample(effect_frame_drops_); - frame_time_data_.AddSample(time_now - previous_frame_time_); - } - previous_frame_time_ = time_now; - effect_frame_drops_ = 0; - adapt_frame_drops_ = 0; + UpdateStats(captured_frame); #endif // VIDEO_FRAME_NAME } @@ -717,6 +708,27 @@ bool VideoCapturer::ShouldFilterFormat(const VideoFormat& format) const { format.height > max_format_->height; } +void VideoCapturer::UpdateStats(const CapturedFrame* captured_frame) { + // Update stats protected from fetches from different thread. + talk_base::CritScope cs(&frame_stats_crit_); + + last_captured_frame_format_.width = captured_frame->width; + last_captured_frame_format_.height = captured_frame->height; + // TODO(ronghuawu): Useful to report interval as well? + last_captured_frame_format_.interval = 0; + last_captured_frame_format_.fourcc = captured_frame->fourcc; + + double time_now = frame_length_time_reporter_.TimerNow(); + if (previous_frame_time_ != 0.0) { + adapt_frame_drops_data_.AddSample(adapt_frame_drops_); + effect_frame_drops_data_.AddSample(effect_frame_drops_); + frame_time_data_.AddSample(time_now - previous_frame_time_); + } + previous_frame_time_ = time_now; + effect_frame_drops_ = 0; + adapt_frame_drops_ = 0; +} + template void VideoCapturer::GetVariableSnapshot( const talk_base::RollingAccumulator& data, diff --git a/talk/media/base/videocapturer.h b/talk/media/base/videocapturer.h index c45ad78f8e..6b1c46ddd3 100644 --- a/talk/media/base/videocapturer.h +++ b/talk/media/base/videocapturer.h @@ -294,7 +294,8 @@ class VideoCapturer // should be called only periodically to log statistics. void GetStats(VariableInfo* adapt_drop_stats, VariableInfo* effect_drop_stats, - VariableInfo* frame_time_stats); + VariableInfo* frame_time_stats, + VideoFormat* last_captured_frame_format); protected: // Callback attached to SignalFrameCaptured where SignalVideoFrames is called. @@ -348,6 +349,8 @@ class VideoCapturer // Returns true if format doesn't fulfill all applied restrictions. bool ShouldFilterFormat(const VideoFormat& format) const; + void UpdateStats(const CapturedFrame* captured_frame); + // Helper function to save statistics on the current data from a // RollingAccumulator into stats. template @@ -385,6 +388,8 @@ class VideoCapturer talk_base::RollingAccumulator effect_frame_drops_data_; double previous_frame_time_; talk_base::RollingAccumulator frame_time_data_; + // The captured frame format before potential adapation. + VideoFormat last_captured_frame_format_; talk_base::CriticalSection crit_; VideoProcessors video_processors_; diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc index 7c057e0e9a..29919d5d0f 100644 --- a/talk/media/webrtc/webrtcvideoengine.cc +++ b/talk/media/webrtc/webrtcvideoengine.cc @@ -2381,20 +2381,22 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options, sinfo.packets_lost = -1; sinfo.fraction_lost = -1; sinfo.rtt_ms = -1; - sinfo.input_frame_width = static_cast(channel_stream_info->width()); - sinfo.input_frame_height = - static_cast(channel_stream_info->height()); VideoCapturer* video_capturer = send_channel->video_capturer(); if (video_capturer) { + VideoFormat last_captured_frame_format; video_capturer->GetStats(&sinfo.adapt_frame_drops, &sinfo.effects_frame_drops, - &sinfo.capturer_frame_time); + &sinfo.capturer_frame_time, + &last_captured_frame_format); + sinfo.input_frame_width = last_captured_frame_format.width; + sinfo.input_frame_height = last_captured_frame_format.height; + } else { + sinfo.input_frame_width = 0; + sinfo.input_frame_height = 0; } webrtc::VideoCodec vie_codec; - // TODO(ronghuawu): Add unit tests to cover the new send stats: - // send_frame_width/height. if (!video_capturer || video_capturer->IsMuted()) { sinfo.send_frame_width = 0; sinfo.send_frame_height = 0;