| Index: chromecast/media/cma/pipeline/video_pipeline_impl.cc
|
| diff --git a/chromecast/media/cma/pipeline/video_pipeline_impl.cc b/chromecast/media/cma/pipeline/video_pipeline_impl.cc
|
| index 6b480c62be6bff5df371579f34fe5d16b77d924c..3498d9daf27be91118954b2fe7494ea21b600b43 100644
|
| --- a/chromecast/media/cma/pipeline/video_pipeline_impl.cc
|
| +++ b/chromecast/media/cma/pipeline/video_pipeline_impl.cc
|
| @@ -8,6 +8,8 @@
|
| #include <utility>
|
|
|
| #include "base/bind.h"
|
| +#include "base/time/time.h"
|
| +#include "chromecast/base/metrics/cast_metrics_helper.h"
|
| #include "chromecast/media/cdm/browser_cdm_cast.h"
|
| #include "chromecast/media/cma/base/buffering_defs.h"
|
| #include "chromecast/media/cma/base/cma_logging.h"
|
| @@ -23,6 +25,15 @@ namespace media {
|
|
|
| namespace {
|
| const size_t kMaxVideoFrameSize = 1024 * 1024;
|
| +
|
| +void LogEstimatedVideoBitrate(int bitrate) {
|
| + CMALOG(kLogControl) << "Estimated video bitrate is " << bitrate << " kbps";
|
| + chromecast::metrics::CastMetricsHelper* metrics_helper =
|
| + chromecast::metrics::CastMetricsHelper::GetInstance();
|
| + metrics_helper->RecordSimpleActionWithValue("Cast.Platform.VideoBitrate",
|
| + bitrate);
|
| +}
|
| +
|
| }
|
|
|
| VideoPipelineImpl::VideoPipelineImpl(
|
| @@ -30,7 +41,10 @@ VideoPipelineImpl::VideoPipelineImpl(
|
| const VideoPipelineClient& client)
|
| : AvPipelineImpl(decoder, client.av_pipeline_client),
|
| video_decoder_(decoder),
|
| - natural_size_changed_cb_(client.natural_size_changed_cb) {
|
| + natural_size_changed_cb_(client.natural_size_changed_cb),
|
| + last_sample_time_(base::Time()),
|
| + elapsed_time_delta_(base::TimeDelta()),
|
| + video_bytes_for_bitrate_estimation_(0) {
|
| DCHECK(video_decoder_);
|
| }
|
|
|
| @@ -117,6 +131,25 @@ void VideoPipelineImpl::UpdateStatistics() {
|
| delta_stats.video_frames_dropped =
|
| current_stats.video_frames_dropped - previous_stats_.video_frames_dropped;
|
|
|
| + base::Time current_time = base::Time::Now();
|
| + elapsed_time_delta_ += current_time - last_sample_time_;
|
| + video_bytes_for_bitrate_estimation_ += delta_stats.video_bytes_decoded;
|
| +
|
| + if (state() != kPlaying) {
|
| + // Invalidate any data that was collected in a window where we were not in
|
| + // the playing state.
|
| + elapsed_time_delta_ = base::TimeDelta::FromSeconds(0);
|
| + video_bytes_for_bitrate_estimation_ = 0;
|
| + } else if (elapsed_time_delta_.InMilliseconds() > 5000) {
|
| + int estimated_bitrate_in_kbps = 8 * video_bytes_for_bitrate_estimation_ /
|
| + elapsed_time_delta_.InMilliseconds();
|
| + if (estimated_bitrate_in_kbps > 0) {
|
| + LogEstimatedVideoBitrate(estimated_bitrate_in_kbps);
|
| + }
|
| + elapsed_time_delta_ = base::TimeDelta::FromSeconds(0);
|
| + video_bytes_for_bitrate_estimation_ = 0;
|
| + }
|
| + last_sample_time_ = current_time;
|
| previous_stats_ = current_stats;
|
|
|
| client().statistics_cb.Run(delta_stats);
|
|
|