Chromium Code Reviews| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram_macros.h" | |
| 8 #include "media/base/audio_buffer.h" | 9 #include "media/base/audio_buffer.h" |
| 9 #include "media/base/audio_decoder.h" | 10 #include "media/base/audio_decoder.h" |
| 10 #include "media/base/audio_decoder_config.h" | 11 #include "media/base/audio_decoder_config.h" |
| 11 #include "media/base/video_decoder.h" | 12 #include "media/base/video_decoder.h" |
| 12 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 | 16 |
| 16 // Audio decoder stream traits implementation. | 17 // Audio decoder stream traits implementation. |
| 17 | 18 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 audio_ts_validator_->CheckForTimestampGap(buffer); | 71 audio_ts_validator_->CheckForTimestampGap(buffer); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void DecoderStreamTraits<DemuxerStream::AUDIO>::OnDecodeDone( | 74 void DecoderStreamTraits<DemuxerStream::AUDIO>::OnDecodeDone( |
| 74 const scoped_refptr<OutputType>& buffer) { | 75 const scoped_refptr<OutputType>& buffer) { |
| 75 audio_ts_validator_->RecordOutputDuration(buffer); | 76 audio_ts_validator_->RecordOutputDuration(buffer); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Video decoder stream traits implementation. | 79 // Video decoder stream traits implementation. |
| 79 | 80 |
| 81 namespace { | |
|
DaleCurtis
2016/12/03 01:24:57
Just inline this if it's only used in one spot. Ad
whywhat
2016/12/05 19:20:20
I just guessed :) How would you choose the number
| |
| 82 | |
| 83 const size_t kKeyframeDistanceAverageDepth = 10; | |
| 84 | |
| 85 } // anonymous namespace | |
| 86 | |
| 80 // static | 87 // static |
| 81 std::string DecoderStreamTraits<DemuxerStream::VIDEO>::ToString() { | 88 std::string DecoderStreamTraits<DemuxerStream::VIDEO>::ToString() { |
| 82 return "video"; | 89 return "video"; |
| 83 } | 90 } |
| 84 | 91 |
| 85 // static | 92 // static |
| 86 bool DecoderStreamTraits<DemuxerStream::VIDEO>::NeedsBitstreamConversion( | 93 bool DecoderStreamTraits<DemuxerStream::VIDEO>::NeedsBitstreamConversion( |
| 87 DecoderType* decoder) { | 94 DecoderType* decoder) { |
| 88 return decoder->NeedsBitstreamConversion(); | 95 return decoder->NeedsBitstreamConversion(); |
| 89 } | 96 } |
| 90 | 97 |
| 91 // static | 98 // static |
| 92 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( | 99 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( |
| 93 const StatisticsCB& statistics_cb, | 100 const StatisticsCB& statistics_cb, |
| 94 int bytes_decoded) { | 101 int bytes_decoded) { |
| 95 PipelineStatistics statistics; | 102 PipelineStatistics statistics; |
| 96 statistics.video_bytes_decoded = bytes_decoded; | 103 statistics.video_bytes_decoded = bytes_decoded; |
| 97 statistics_cb.Run(statistics); | 104 statistics_cb.Run(statistics); |
| 98 } | 105 } |
| 99 | 106 |
| 100 // static | 107 // static |
| 101 scoped_refptr<DecoderStreamTraits<DemuxerStream::VIDEO>::OutputType> | 108 scoped_refptr<DecoderStreamTraits<DemuxerStream::VIDEO>::OutputType> |
| 102 DecoderStreamTraits<DemuxerStream::VIDEO>::CreateEOSOutput() { | 109 DecoderStreamTraits<DemuxerStream::VIDEO>::CreateEOSOutput() { |
| 103 return OutputType::CreateEOSFrame(); | 110 return OutputType::CreateEOSFrame(); |
| 104 } | 111 } |
| 105 | 112 |
| 113 DecoderStreamTraits<DemuxerStream::VIDEO>::DecoderStreamTraits( | |
| 114 const scoped_refptr<MediaLog>& media_log) | |
| 115 : keyframe_distance_average_(kKeyframeDistanceAverageDepth) {} | |
| 116 | |
| 106 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( | 117 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( |
| 107 DecoderType* decoder, | 118 DecoderType* decoder, |
| 108 DemuxerStream* stream, | 119 DemuxerStream* stream, |
| 109 CdmContext* cdm_context, | 120 CdmContext* cdm_context, |
| 110 const InitCB& init_cb, | 121 const InitCB& init_cb, |
| 111 const OutputCB& output_cb) { | 122 const OutputCB& output_cb) { |
| 112 DCHECK(stream->video_decoder_config().IsValidConfig()); | 123 DCHECK(stream->video_decoder_config().IsValidConfig()); |
| 113 decoder->Initialize(stream->video_decoder_config(), | 124 decoder->Initialize(stream->video_decoder_config(), |
| 114 stream->liveness() == DemuxerStream::LIVENESS_LIVE, | 125 stream->liveness() == DemuxerStream::LIVENESS_LIVE, |
| 115 cdm_context, init_cb, output_cb); | 126 cdm_context, init_cb, output_cb); |
| 116 } | 127 } |
| 117 | 128 |
| 129 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnStreamReset( | |
| 130 DemuxerStream* stream) { | |
| 131 DCHECK(stream); | |
| 132 ResetMetrics(); | |
|
DaleCurtis
2016/12/03 01:24:57
Why bother if we only care about the max value? Th
whywhat
2016/12/05 19:20:20
I'm not entirely sure when OnStreamReset is called
| |
| 133 max_average_ = base::TimeDelta(); | |
| 134 } | |
| 135 | |
| 136 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnDecode( | |
| 137 const scoped_refptr<DecoderBuffer>& buffer) { | |
| 138 if (!buffer.get()) | |
|
DaleCurtis
2016/12/03 01:24:57
Drop .get()
| |
| 139 return; | |
| 140 | |
| 141 if (buffer->end_of_stream()) { | |
| 142 ResetMetrics(); | |
| 143 return; | |
| 144 } | |
| 145 | |
| 146 if (!buffer->is_key_frame()) | |
| 147 return; | |
| 148 | |
| 149 base::TimeDelta current_frame_timestamp = buffer->timestamp(); | |
| 150 if (last_keyframe_timestamp_.is_zero()) { | |
| 151 last_keyframe_timestamp_ = current_frame_timestamp; | |
| 152 return; | |
| 153 } | |
| 154 | |
| 155 base::TimeDelta last_keyframe_distance = | |
| 156 current_frame_timestamp - last_keyframe_timestamp_; | |
| 157 last_keyframe_timestamp_ = current_frame_timestamp; | |
| 158 keyframe_distance_average_.AddSample(last_keyframe_distance); | |
| 159 base::TimeDelta new_average = keyframe_distance_average_.Average(); | |
| 160 if (new_average > max_average_) { | |
| 161 max_average_ = new_average; | |
| 162 UMA_HISTOGRAM_MEDIUM_TIMES("Media.Video.KeyFrameDistanceAverage", | |
|
DaleCurtis
2016/12/03 01:24:57
I wonder if instead you just want to record every
whywhat
2016/12/05 19:20:20
For UMA, perhaps, but when we try to decide whethe
| |
| 163 new_average); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 void DecoderStreamTraits<DemuxerStream::VIDEO>::ResetMetrics() { | |
| 168 keyframe_distance_average_.Reset(); | |
| 169 last_keyframe_timestamp_ = base::TimeDelta(); | |
| 170 } | |
| 171 | |
| 118 } // namespace media | 172 } // namespace media |
| OLD | NEW |