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 "media/filters/decoder_stream_traits.h" | 5 #include "media/filters/decoder_stream_traits.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 const scoped_refptr<MediaLog>& media_log) | 100 const scoped_refptr<MediaLog>& media_log) |
101 // Randomly selected number of samples to keep. | 101 // Randomly selected number of samples to keep. |
102 : keyframe_distance_average_(16) {} | 102 : keyframe_distance_average_(16) {} |
103 | 103 |
104 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( | 104 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( |
105 const StatisticsCB& statistics_cb, | 105 const StatisticsCB& statistics_cb, |
106 int bytes_decoded) { | 106 int bytes_decoded) { |
107 PipelineStatistics statistics; | 107 PipelineStatistics statistics; |
108 statistics.video_bytes_decoded = bytes_decoded; | 108 statistics.video_bytes_decoded = bytes_decoded; |
109 | 109 |
110 // Before we have enough keyframes to calculate the average distance, we will | 110 if (keyframe_distance_average_.count()) { |
111 // assume the average keyframe distance is infinitely large. | |
112 if (keyframe_distance_average_.count() < 3) { | |
113 statistics.video_keyframe_distance_average = base::TimeDelta::Max(); | |
114 } else { | |
115 statistics.video_keyframe_distance_average = | 111 statistics.video_keyframe_distance_average = |
116 keyframe_distance_average_.Average(); | 112 keyframe_distance_average_.Average(); |
| 113 } else { |
| 114 // Before we have enough keyframes to calculate the average distance, we |
| 115 // will assume the average keyframe distance is infinitely large. |
| 116 statistics.video_keyframe_distance_average = base::TimeDelta::Max(); |
117 } | 117 } |
118 | 118 |
119 statistics_cb.Run(statistics); | 119 statistics_cb.Run(statistics); |
120 } | 120 } |
121 | 121 |
122 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( | 122 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( |
123 DecoderType* decoder, | 123 DecoderType* decoder, |
124 DemuxerStream* stream, | 124 DemuxerStream* stream, |
125 CdmContext* cdm_context, | 125 CdmContext* cdm_context, |
126 const InitCB& init_cb, | 126 const InitCB& init_cb, |
127 const OutputCB& output_cb) { | 127 const OutputCB& output_cb) { |
128 DCHECK(stream->video_decoder_config().IsValidConfig()); | 128 DCHECK(stream->video_decoder_config().IsValidConfig()); |
129 decoder->Initialize(stream->video_decoder_config(), | 129 decoder->Initialize(stream->video_decoder_config(), |
130 stream->liveness() == DemuxerStream::LIVENESS_LIVE, | 130 stream->liveness() == DemuxerStream::LIVENESS_LIVE, |
131 cdm_context, init_cb, output_cb); | 131 cdm_context, init_cb, output_cb); |
132 } | 132 } |
133 | 133 |
134 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnStreamReset( | 134 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnStreamReset( |
135 DemuxerStream* stream) { | 135 DemuxerStream* stream) { |
136 DCHECK(stream); | 136 DCHECK(stream); |
137 last_keyframe_timestamp_ = base::TimeDelta(); | 137 last_keyframe_timestamp_ = base::TimeDelta(); |
138 keyframe_distance_average_.Reset(); | |
139 } | 138 } |
140 | 139 |
141 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnDecode( | 140 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnDecode( |
142 const scoped_refptr<DecoderBuffer>& buffer) { | 141 const scoped_refptr<DecoderBuffer>& buffer) { |
143 if (!buffer) | 142 if (!buffer) |
144 return; | 143 return; |
145 | 144 |
146 if (buffer->end_of_stream()) { | 145 if (buffer->end_of_stream()) { |
147 last_keyframe_timestamp_ = base::TimeDelta(); | 146 last_keyframe_timestamp_ = base::TimeDelta(); |
148 return; | 147 return; |
149 } | 148 } |
150 | 149 |
151 if (!buffer->is_key_frame()) | 150 if (!buffer->is_key_frame()) |
152 return; | 151 return; |
153 | 152 |
154 base::TimeDelta current_frame_timestamp = buffer->timestamp(); | 153 base::TimeDelta current_frame_timestamp = buffer->timestamp(); |
155 if (last_keyframe_timestamp_.is_zero()) { | 154 if (last_keyframe_timestamp_.is_zero()) { |
156 last_keyframe_timestamp_ = current_frame_timestamp; | 155 last_keyframe_timestamp_ = current_frame_timestamp; |
157 return; | 156 return; |
158 } | 157 } |
159 | 158 |
160 base::TimeDelta frame_distance = | 159 base::TimeDelta frame_distance = |
161 current_frame_timestamp - last_keyframe_timestamp_; | 160 current_frame_timestamp - last_keyframe_timestamp_; |
162 UMA_HISTOGRAM_MEDIUM_TIMES("Media.Video.KeyFrameDistance", frame_distance); | 161 UMA_HISTOGRAM_MEDIUM_TIMES("Media.Video.KeyFrameDistance", frame_distance); |
163 last_keyframe_timestamp_ = current_frame_timestamp; | 162 last_keyframe_timestamp_ = current_frame_timestamp; |
164 keyframe_distance_average_.AddSample(frame_distance); | 163 keyframe_distance_average_.AddSample(frame_distance); |
165 } | 164 } |
166 | 165 |
167 } // namespace media | 166 } // namespace media |
OLD | NEW |