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 <limits> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 9 #include "media/base/audio_buffer.h" | 11 #include "media/base/audio_buffer.h" |
| 10 #include "media/base/audio_decoder.h" | 12 #include "media/base/audio_decoder.h" |
| 11 #include "media/base/audio_decoder_config.h" | 13 #include "media/base/audio_decoder_config.h" |
| 12 #include "media/base/video_decoder.h" | 14 #include "media/base/video_decoder.h" |
| 13 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 14 | 16 |
| 15 namespace media { | 17 namespace media { |
| 16 | 18 |
| 17 // Audio decoder stream traits implementation. | 19 // Audio decoder stream traits implementation. |
| 18 | 20 |
| 19 // static | 21 // static |
| 20 std::string DecoderStreamTraits<DemuxerStream::AUDIO>::ToString() { | 22 std::string DecoderStreamTraits<DemuxerStream::AUDIO>::ToString() { |
| 21 return "audio"; | 23 return "audio"; |
| 22 } | 24 } |
| 23 | 25 |
| 24 // static | 26 // static |
| 25 bool DecoderStreamTraits<DemuxerStream::AUDIO>::NeedsBitstreamConversion( | 27 bool DecoderStreamTraits<DemuxerStream::AUDIO>::NeedsBitstreamConversion( |
| 26 DecoderType* decoder) { | 28 DecoderType* decoder) { |
| 27 return decoder->NeedsBitstreamConversion(); | 29 return decoder->NeedsBitstreamConversion(); |
| 28 } | 30 } |
| 29 | 31 |
| 30 // static | 32 // static |
| 31 void DecoderStreamTraits<DemuxerStream::AUDIO>::ReportStatistics( | |
| 32 const StatisticsCB& statistics_cb, | |
| 33 int bytes_decoded) { | |
| 34 PipelineStatistics statistics; | |
| 35 statistics.audio_bytes_decoded = bytes_decoded; | |
| 36 statistics_cb.Run(statistics); | |
| 37 } | |
| 38 | |
| 39 // static | |
| 40 scoped_refptr<DecoderStreamTraits<DemuxerStream::AUDIO>::OutputType> | 33 scoped_refptr<DecoderStreamTraits<DemuxerStream::AUDIO>::OutputType> |
| 41 DecoderStreamTraits<DemuxerStream::AUDIO>::CreateEOSOutput() { | 34 DecoderStreamTraits<DemuxerStream::AUDIO>::CreateEOSOutput() { |
| 42 return OutputType::CreateEOSBuffer(); | 35 return OutputType::CreateEOSBuffer(); |
| 43 } | 36 } |
| 44 | 37 |
| 45 DecoderStreamTraits<DemuxerStream::AUDIO>::DecoderStreamTraits( | 38 DecoderStreamTraits<DemuxerStream::AUDIO>::DecoderStreamTraits( |
| 46 const scoped_refptr<MediaLog>& media_log) | 39 const scoped_refptr<MediaLog>& media_log) |
| 47 : media_log_(media_log) {} | 40 : media_log_(media_log) {} |
| 48 | 41 |
| 42 void DecoderStreamTraits<DemuxerStream::AUDIO>::ReportStatistics( | |
| 43 const StatisticsCB& statistics_cb, | |
| 44 int bytes_decoded) { | |
| 45 PipelineStatistics statistics; | |
| 46 statistics.audio_bytes_decoded = bytes_decoded; | |
| 47 statistics_cb.Run(statistics); | |
| 48 } | |
| 49 | |
| 49 void DecoderStreamTraits<DemuxerStream::AUDIO>::InitializeDecoder( | 50 void DecoderStreamTraits<DemuxerStream::AUDIO>::InitializeDecoder( |
| 50 DecoderType* decoder, | 51 DecoderType* decoder, |
| 51 DemuxerStream* stream, | 52 DemuxerStream* stream, |
| 52 CdmContext* cdm_context, | 53 CdmContext* cdm_context, |
| 53 const InitCB& init_cb, | 54 const InitCB& init_cb, |
| 54 const OutputCB& output_cb) { | 55 const OutputCB& output_cb) { |
| 55 DCHECK(stream->audio_decoder_config().IsValidConfig()); | 56 DCHECK(stream->audio_decoder_config().IsValidConfig()); |
| 56 decoder->Initialize(stream->audio_decoder_config(), cdm_context, init_cb, | 57 decoder->Initialize(stream->audio_decoder_config(), cdm_context, init_cb, |
| 57 output_cb); | 58 output_cb); |
| 58 } | 59 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 83 return "video"; | 84 return "video"; |
| 84 } | 85 } |
| 85 | 86 |
| 86 // static | 87 // static |
| 87 bool DecoderStreamTraits<DemuxerStream::VIDEO>::NeedsBitstreamConversion( | 88 bool DecoderStreamTraits<DemuxerStream::VIDEO>::NeedsBitstreamConversion( |
| 88 DecoderType* decoder) { | 89 DecoderType* decoder) { |
| 89 return decoder->NeedsBitstreamConversion(); | 90 return decoder->NeedsBitstreamConversion(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 // static | 93 // static |
| 94 scoped_refptr<DecoderStreamTraits<DemuxerStream::VIDEO>::OutputType> | |
| 95 DecoderStreamTraits<DemuxerStream::VIDEO>::CreateEOSOutput() { | |
| 96 return OutputType::CreateEOSFrame(); | |
| 97 } | |
| 98 | |
| 99 DecoderStreamTraits<DemuxerStream::VIDEO>::DecoderStreamTraits( | |
| 100 const scoped_refptr<MediaLog>& media_log) | |
| 101 // Randomly selected number of samples to keep. | |
| 102 : keyframe_distance_average_(16) {} | |
| 103 | |
| 93 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( | 104 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( |
| 94 const StatisticsCB& statistics_cb, | 105 const StatisticsCB& statistics_cb, |
| 95 int bytes_decoded) { | 106 int bytes_decoded) { |
| 96 PipelineStatistics statistics; | 107 PipelineStatistics statistics; |
| 97 statistics.video_bytes_decoded = bytes_decoded; | 108 statistics.video_bytes_decoded = bytes_decoded; |
| 109 | |
| 110 // Before we have enough keyframes to calculate the average distance, we will | |
| 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(); | |
|
DaleCurtis
2017/01/11 23:44:48
We typically use kNoTimestamp() in media for this.
whywhat
2017/01/12 00:16:32
That would be a minimum value though so we will en
DaleCurtis
2017/01/12 01:13:38
Ah, I guess that works, but anyone looking at stat
| |
| 114 } else { | |
| 115 statistics.video_keyframe_distance_average = | |
| 116 keyframe_distance_average_.Average(); | |
| 117 } | |
| 118 | |
| 98 statistics_cb.Run(statistics); | 119 statistics_cb.Run(statistics); |
| 99 } | 120 } |
| 100 | 121 |
| 101 // static | |
| 102 scoped_refptr<DecoderStreamTraits<DemuxerStream::VIDEO>::OutputType> | |
| 103 DecoderStreamTraits<DemuxerStream::VIDEO>::CreateEOSOutput() { | |
| 104 return OutputType::CreateEOSFrame(); | |
| 105 } | |
| 106 | |
| 107 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( | 122 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( |
| 108 DecoderType* decoder, | 123 DecoderType* decoder, |
| 109 DemuxerStream* stream, | 124 DemuxerStream* stream, |
| 110 CdmContext* cdm_context, | 125 CdmContext* cdm_context, |
| 111 const InitCB& init_cb, | 126 const InitCB& init_cb, |
| 112 const OutputCB& output_cb) { | 127 const OutputCB& output_cb) { |
| 113 DCHECK(stream->video_decoder_config().IsValidConfig()); | 128 DCHECK(stream->video_decoder_config().IsValidConfig()); |
| 114 decoder->Initialize(stream->video_decoder_config(), | 129 decoder->Initialize(stream->video_decoder_config(), |
| 115 stream->liveness() == DemuxerStream::LIVENESS_LIVE, | 130 stream->liveness() == DemuxerStream::LIVENESS_LIVE, |
| 116 cdm_context, init_cb, output_cb); | 131 cdm_context, init_cb, output_cb); |
| 117 } | 132 } |
| 118 | 133 |
| 119 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnStreamReset( | 134 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnStreamReset( |
| 120 DemuxerStream* stream) { | 135 DemuxerStream* stream) { |
| 121 DCHECK(stream); | 136 DCHECK(stream); |
| 122 last_keyframe_timestamp_ = base::TimeDelta(); | 137 last_keyframe_timestamp_ = base::TimeDelta(); |
| 138 keyframe_distance_average_.Reset(); | |
| 123 } | 139 } |
| 124 | 140 |
| 125 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnDecode( | 141 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnDecode( |
| 126 const scoped_refptr<DecoderBuffer>& buffer) { | 142 const scoped_refptr<DecoderBuffer>& buffer) { |
| 127 if (!buffer) | 143 if (!buffer) |
| 128 return; | 144 return; |
| 129 | 145 |
| 130 if (buffer->end_of_stream()) { | 146 if (buffer->end_of_stream()) { |
| 131 last_keyframe_timestamp_ = base::TimeDelta(); | 147 last_keyframe_timestamp_ = base::TimeDelta(); |
| 132 return; | 148 return; |
| 133 } | 149 } |
| 134 | 150 |
| 135 if (!buffer->is_key_frame()) | 151 if (!buffer->is_key_frame()) |
| 136 return; | 152 return; |
| 137 | 153 |
| 138 base::TimeDelta current_frame_timestamp = buffer->timestamp(); | 154 base::TimeDelta current_frame_timestamp = buffer->timestamp(); |
| 139 if (last_keyframe_timestamp_.is_zero()) { | 155 if (last_keyframe_timestamp_.is_zero()) { |
| 140 last_keyframe_timestamp_ = current_frame_timestamp; | 156 last_keyframe_timestamp_ = current_frame_timestamp; |
| 141 return; | 157 return; |
| 142 } | 158 } |
| 143 | 159 |
| 144 UMA_HISTOGRAM_MEDIUM_TIMES( | 160 base::TimeDelta frame_distance = |
| 145 "Media.Video.KeyFrameDistance", | 161 current_frame_timestamp - last_keyframe_timestamp_; |
| 146 current_frame_timestamp - last_keyframe_timestamp_); | 162 UMA_HISTOGRAM_MEDIUM_TIMES("Media.Video.KeyFrameDistance", frame_distance); |
| 147 last_keyframe_timestamp_ = current_frame_timestamp; | 163 last_keyframe_timestamp_ = current_frame_timestamp; |
| 164 keyframe_distance_average_.AddSample(frame_distance); | |
| 148 } | 165 } |
| 149 | 166 |
| 150 } // namespace media | 167 } // namespace media |
| OLD | NEW |