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/video_pipeline_impl.h" | 5 #include "chromecast/media/cma/pipeline/video_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/cdm/browser_cdm_cast.h" | 13 #include "chromecast/media/cdm/browser_cdm_cast.h" |
12 #include "chromecast/media/cma/base/buffering_defs.h" | 14 #include "chromecast/media/cma/base/buffering_defs.h" |
13 #include "chromecast/media/cma/base/cma_logging.h" | 15 #include "chromecast/media/cma/base/cma_logging.h" |
14 #include "chromecast/media/cma/base/coded_frame_provider.h" | 16 #include "chromecast/media/cma/base/coded_frame_provider.h" |
15 #include "chromecast/media/cma/base/decoder_config_adapter.h" | 17 #include "chromecast/media/cma/base/decoder_config_adapter.h" |
16 #include "chromecast/media/cma/pipeline/av_pipeline_impl.h" | 18 #include "chromecast/media/cma/pipeline/av_pipeline_impl.h" |
17 #include "chromecast/public/graphics_types.h" | 19 #include "chromecast/public/graphics_types.h" |
18 #include "chromecast/public/media/decoder_config.h" | 20 #include "chromecast/public/media/decoder_config.h" |
19 #include "media/base/video_decoder_config.h" | 21 #include "media/base/video_decoder_config.h" |
20 | 22 |
21 namespace chromecast { | 23 namespace chromecast { |
22 namespace media { | 24 namespace media { |
23 | 25 |
24 namespace { | 26 namespace { |
25 const size_t kMaxVideoFrameSize = 1024 * 1024; | 27 const size_t kMaxVideoFrameSize = 1024 * 1024; |
| 28 |
| 29 void LogEstimatedVideoBitrate(int bitrate) { |
| 30 CMALOG(kLogControl) << "Estimated video bitrate is " << bitrate << " kbps"; |
| 31 chromecast::metrics::CastMetricsHelper* metrics_helper = |
| 32 chromecast::metrics::CastMetricsHelper::GetInstance(); |
| 33 metrics_helper->RecordSimpleActionWithValue("Cast.Platform.VideoBitrate", |
| 34 bitrate); |
| 35 } |
| 36 |
26 } | 37 } |
27 | 38 |
28 VideoPipelineImpl::VideoPipelineImpl( | 39 VideoPipelineImpl::VideoPipelineImpl( |
29 MediaPipelineBackend::VideoDecoder* decoder, | 40 MediaPipelineBackend::VideoDecoder* decoder, |
30 const VideoPipelineClient& client) | 41 const VideoPipelineClient& client) |
31 : AvPipelineImpl(decoder, client.av_pipeline_client), | 42 : AvPipelineImpl(decoder, client.av_pipeline_client), |
32 video_decoder_(decoder), | 43 video_decoder_(decoder), |
33 natural_size_changed_cb_(client.natural_size_changed_cb) { | 44 natural_size_changed_cb_(client.natural_size_changed_cb), |
| 45 last_sample_time_(base::Time()), |
| 46 elapsed_time_delta_(base::TimeDelta()), |
| 47 video_bytes_for_bitrate_estimation_(0) { |
34 DCHECK(video_decoder_); | 48 DCHECK(video_decoder_); |
35 } | 49 } |
36 | 50 |
37 VideoPipelineImpl::~VideoPipelineImpl() { | 51 VideoPipelineImpl::~VideoPipelineImpl() { |
38 } | 52 } |
39 | 53 |
40 ::media::PipelineStatus VideoPipelineImpl::Initialize( | 54 ::media::PipelineStatus VideoPipelineImpl::Initialize( |
41 const std::vector<::media::VideoDecoderConfig>& configs, | 55 const std::vector<::media::VideoDecoderConfig>& configs, |
42 scoped_ptr<CodedFrameProvider> frame_provider) { | 56 scoped_ptr<CodedFrameProvider> frame_provider) { |
43 DCHECK_GT(configs.size(), 0u); | 57 DCHECK_GT(configs.size(), 0u); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 current_stats.video_frames_dropped = video_stats.dropped_frames; | 124 current_stats.video_frames_dropped = video_stats.dropped_frames; |
111 | 125 |
112 ::media::PipelineStatistics delta_stats; | 126 ::media::PipelineStatistics delta_stats; |
113 delta_stats.video_bytes_decoded = | 127 delta_stats.video_bytes_decoded = |
114 current_stats.video_bytes_decoded - previous_stats_.video_bytes_decoded; | 128 current_stats.video_bytes_decoded - previous_stats_.video_bytes_decoded; |
115 delta_stats.video_frames_decoded = | 129 delta_stats.video_frames_decoded = |
116 current_stats.video_frames_decoded - previous_stats_.video_frames_decoded; | 130 current_stats.video_frames_decoded - previous_stats_.video_frames_decoded; |
117 delta_stats.video_frames_dropped = | 131 delta_stats.video_frames_dropped = |
118 current_stats.video_frames_dropped - previous_stats_.video_frames_dropped; | 132 current_stats.video_frames_dropped - previous_stats_.video_frames_dropped; |
119 | 133 |
| 134 base::Time current_time = base::Time::Now(); |
| 135 elapsed_time_delta_ += current_time - last_sample_time_; |
| 136 video_bytes_for_bitrate_estimation_ += delta_stats.video_bytes_decoded; |
| 137 |
| 138 if (state() != kPlaying) { |
| 139 // Invalidate any data that was collected in a window where we were not in |
| 140 // the playing state. |
| 141 elapsed_time_delta_ = base::TimeDelta::FromSeconds(0); |
| 142 video_bytes_for_bitrate_estimation_ = 0; |
| 143 } else if (elapsed_time_delta_.InMilliseconds() > 5000) { |
| 144 int estimated_bitrate_in_kbps = 8 * video_bytes_for_bitrate_estimation_ / |
| 145 elapsed_time_delta_.InMilliseconds(); |
| 146 if (estimated_bitrate_in_kbps > 0) { |
| 147 LogEstimatedVideoBitrate(estimated_bitrate_in_kbps); |
| 148 } |
| 149 elapsed_time_delta_ = base::TimeDelta::FromSeconds(0); |
| 150 video_bytes_for_bitrate_estimation_ = 0; |
| 151 } |
| 152 last_sample_time_ = current_time; |
120 previous_stats_ = current_stats; | 153 previous_stats_ = current_stats; |
121 | 154 |
122 client().statistics_cb.Run(delta_stats); | 155 client().statistics_cb.Run(delta_stats); |
123 } | 156 } |
124 | 157 |
125 } // namespace media | 158 } // namespace media |
126 } // namespace chromecast | 159 } // namespace chromecast |
OLD | NEW |