OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/media/cma/pipeline/audio_pipeline_impl.h" | 5 #include "chromecast/media/cma/pipeline/audio_pipeline_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/time/time.h" | |
12 #include "chromecast/base/metrics/cast_metrics_helper.h" | |
11 #include "chromecast/media/cma/base/buffering_defs.h" | 13 #include "chromecast/media/cma/base/buffering_defs.h" |
12 #include "chromecast/media/cma/base/cma_logging.h" | 14 #include "chromecast/media/cma/base/cma_logging.h" |
13 #include "chromecast/media/cma/base/coded_frame_provider.h" | 15 #include "chromecast/media/cma/base/coded_frame_provider.h" |
14 #include "chromecast/media/cma/base/decoder_config_adapter.h" | 16 #include "chromecast/media/cma/base/decoder_config_adapter.h" |
15 #include "chromecast/public/media/decoder_config.h" | 17 #include "chromecast/public/media/decoder_config.h" |
16 #include "media/base/audio_decoder_config.h" | 18 #include "media/base/audio_decoder_config.h" |
17 | 19 |
18 namespace chromecast { | 20 namespace chromecast { |
19 namespace media { | 21 namespace media { |
20 | 22 |
21 namespace { | 23 namespace { |
22 const size_t kMaxAudioFrameSize = 32 * 1024; | 24 const size_t kMaxAudioFrameSize = 32 * 1024; |
25 | |
26 void LogEstimatedAudioBitrate(int bitrate) { | |
27 CMALOG(kLogControl) << "Estimated audio bitrate is " << bitrate << " kbps"; | |
28 chromecast::metrics::CastMetricsHelper* metrics_helper = | |
29 chromecast::metrics::CastMetricsHelper::GetInstance(); | |
halliwell
2016/03/10 17:57:54
nit, no need for 'chromecast::'
ejason
2016/03/11 00:24:45
Done.
| |
30 metrics_helper->RecordSimpleActionWithValue("Cast.Platform.AudioBitrate", | |
31 bitrate); | |
32 } | |
33 | |
23 } | 34 } |
24 | 35 |
25 AudioPipelineImpl::AudioPipelineImpl( | 36 AudioPipelineImpl::AudioPipelineImpl( |
26 MediaPipelineBackend::AudioDecoder* decoder, | 37 MediaPipelineBackend::AudioDecoder* decoder, |
27 const AvPipelineClient& client) | 38 const AvPipelineClient& client) |
28 : AvPipelineImpl(decoder, client), audio_decoder_(decoder) { | 39 : AvPipelineImpl(decoder, client), |
40 audio_decoder_(decoder), | |
41 last_sample_time_(base::Time()), | |
42 elapsed_time_delta_(base::TimeDelta()), | |
43 audio_bytes_for_bitrate_estimation_(0) { | |
29 DCHECK(audio_decoder_); | 44 DCHECK(audio_decoder_); |
30 } | 45 } |
31 | 46 |
32 AudioPipelineImpl::~AudioPipelineImpl() {} | 47 AudioPipelineImpl::~AudioPipelineImpl() {} |
33 | 48 |
34 ::media::PipelineStatus AudioPipelineImpl::Initialize( | 49 ::media::PipelineStatus AudioPipelineImpl::Initialize( |
35 const ::media::AudioDecoderConfig& audio_config, | 50 const ::media::AudioDecoderConfig& audio_config, |
36 scoped_ptr<CodedFrameProvider> frame_provider) { | 51 scoped_ptr<CodedFrameProvider> frame_provider) { |
37 CMALOG(kLogControl) << __FUNCTION__ << " " | 52 CMALOG(kLogControl) << __FUNCTION__ << " " |
38 << audio_config.AsHumanReadableString(); | 53 << audio_config.AsHumanReadableString(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 MediaPipelineBackend::AudioDecoder::Statistics audio_stats; | 92 MediaPipelineBackend::AudioDecoder::Statistics audio_stats; |
78 audio_decoder_->GetStatistics(&audio_stats); | 93 audio_decoder_->GetStatistics(&audio_stats); |
79 | 94 |
80 ::media::PipelineStatistics current_stats; | 95 ::media::PipelineStatistics current_stats; |
81 current_stats.audio_bytes_decoded = audio_stats.decoded_bytes; | 96 current_stats.audio_bytes_decoded = audio_stats.decoded_bytes; |
82 | 97 |
83 ::media::PipelineStatistics delta_stats; | 98 ::media::PipelineStatistics delta_stats; |
84 delta_stats.audio_bytes_decoded = | 99 delta_stats.audio_bytes_decoded = |
85 current_stats.audio_bytes_decoded - previous_stats_.audio_bytes_decoded; | 100 current_stats.audio_bytes_decoded - previous_stats_.audio_bytes_decoded; |
86 | 101 |
102 base::Time current_time = base::Time::Now(); | |
103 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
| |
104 audio_bytes_for_bitrate_estimation_ += delta_stats.audio_bytes_decoded; | |
105 | |
106 if (state() != kPlaying) { | |
107 // Invalidate any data that was collected in a window where we were not in | |
108 // the playing state. | |
109 elapsed_time_delta_ = base::TimeDelta::FromSeconds(0); | |
110 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
| |
111 } else if (elapsed_time_delta_.InMilliseconds() > 5000) { | |
112 int estimated_bitrate_in_kbps = 8 * audio_bytes_for_bitrate_estimation_ / | |
113 elapsed_time_delta_.InMilliseconds(); | |
114 if (estimated_bitrate_in_kbps > 0) { | |
115 LogEstimatedAudioBitrate(estimated_bitrate_in_kbps); | |
116 } | |
117 elapsed_time_delta_ = base::TimeDelta::FromSeconds(0); | |
118 audio_bytes_for_bitrate_estimation_ = 0; | |
119 } | |
120 last_sample_time_ = current_time; | |
87 previous_stats_ = current_stats; | 121 previous_stats_ = current_stats; |
88 | 122 |
89 client().statistics_cb.Run(delta_stats); | 123 client().statistics_cb.Run(delta_stats); |
90 } | 124 } |
91 | 125 |
92 } // namespace media | 126 } // namespace media |
93 } // namespace chromecast | 127 } // namespace chromecast |
OLD | NEW |