Chromium Code Reviews| Index: chromecast/media/cma/pipeline/audio_pipeline_impl.cc |
| diff --git a/chromecast/media/cma/pipeline/audio_pipeline_impl.cc b/chromecast/media/cma/pipeline/audio_pipeline_impl.cc |
| index ab5478b7e7d0c5f5e85820262bd15b893a3a60a2..7c5ee777bd86b8fd510f457953f2877556dd6022 100644 |
| --- a/chromecast/media/cma/pipeline/audio_pipeline_impl.cc |
| +++ b/chromecast/media/cma/pipeline/audio_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/cma/base/buffering_defs.h" |
| #include "chromecast/media/cma/base/cma_logging.h" |
| #include "chromecast/media/cma/base/coded_frame_provider.h" |
| @@ -20,12 +22,25 @@ namespace media { |
| namespace { |
| const size_t kMaxAudioFrameSize = 32 * 1024; |
| + |
| +void LogEstimatedAudioBitrate(int bitrate) { |
| + CMALOG(kLogControl) << "Estimated audio bitrate is " << bitrate << " kbps"; |
| + chromecast::metrics::CastMetricsHelper* metrics_helper = |
| + chromecast::metrics::CastMetricsHelper::GetInstance(); |
|
halliwell
2016/03/10 17:57:54
nit, no need for 'chromecast::'
ejason
2016/03/11 00:24:45
Done.
|
| + metrics_helper->RecordSimpleActionWithValue("Cast.Platform.AudioBitrate", |
| + bitrate); |
| +} |
| + |
| } |
| AudioPipelineImpl::AudioPipelineImpl( |
| MediaPipelineBackend::AudioDecoder* decoder, |
| const AvPipelineClient& client) |
| - : AvPipelineImpl(decoder, client), audio_decoder_(decoder) { |
| + : AvPipelineImpl(decoder, client), |
| + audio_decoder_(decoder), |
| + last_sample_time_(base::Time()), |
| + elapsed_time_delta_(base::TimeDelta()), |
| + audio_bytes_for_bitrate_estimation_(0) { |
| DCHECK(audio_decoder_); |
| } |
| @@ -84,6 +99,25 @@ void AudioPipelineImpl::UpdateStatistics() { |
| delta_stats.audio_bytes_decoded = |
| current_stats.audio_bytes_decoded - previous_stats_.audio_bytes_decoded; |
| + base::Time current_time = base::Time::Now(); |
| + elapsed_time_delta_ += current_time - last_sample_time_; |
|
halliwell
2016/03/10 17:57:54
If the first time this function is called, we're i
ejason
2016/03/11 00:24:45
I've updated the new logic to handle the first-tim
|
| + audio_bytes_for_bitrate_estimation_ += delta_stats.audio_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); |
| + audio_bytes_for_bitrate_estimation_ = 0; |
|
halliwell
2016/03/10 17:57:54
shouldn't we reset these things on state transitio
ejason
2016/03/11 00:24:45
The state transitions are handled in media_pipelin
|
| + } else if (elapsed_time_delta_.InMilliseconds() > 5000) { |
| + int estimated_bitrate_in_kbps = 8 * audio_bytes_for_bitrate_estimation_ / |
| + elapsed_time_delta_.InMilliseconds(); |
| + if (estimated_bitrate_in_kbps > 0) { |
| + LogEstimatedAudioBitrate(estimated_bitrate_in_kbps); |
| + } |
| + elapsed_time_delta_ = base::TimeDelta::FromSeconds(0); |
| + audio_bytes_for_bitrate_estimation_ = 0; |
| + } |
| + last_sample_time_ = current_time; |
| previous_stats_ = current_stats; |
| client().statistics_cb.Run(delta_stats); |