| 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 17 matching lines...) Expand all Loading... |
| 28 DecoderType* decoder) { | 28 DecoderType* decoder) { |
| 29 return decoder->NeedsBitstreamConversion(); | 29 return decoder->NeedsBitstreamConversion(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 scoped_refptr<DecoderStreamTraits<DemuxerStream::AUDIO>::OutputType> | 33 scoped_refptr<DecoderStreamTraits<DemuxerStream::AUDIO>::OutputType> |
| 34 DecoderStreamTraits<DemuxerStream::AUDIO>::CreateEOSOutput() { | 34 DecoderStreamTraits<DemuxerStream::AUDIO>::CreateEOSOutput() { |
| 35 return OutputType::CreateEOSBuffer(); | 35 return OutputType::CreateEOSBuffer(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // static |
| 39 DecoderStreamTraits<DemuxerStream::AUDIO>::DecoderConfigType |
| 40 DecoderStreamTraits<DemuxerStream::AUDIO>::GetDecoderConfig( |
| 41 DemuxerStream* stream) { |
| 42 return stream->audio_decoder_config(); |
| 43 } |
| 44 |
| 38 DecoderStreamTraits<DemuxerStream::AUDIO>::DecoderStreamTraits( | 45 DecoderStreamTraits<DemuxerStream::AUDIO>::DecoderStreamTraits( |
| 39 const scoped_refptr<MediaLog>& media_log) | 46 const scoped_refptr<MediaLog>& media_log) |
| 40 : media_log_(media_log) {} | 47 : media_log_(media_log) {} |
| 41 | 48 |
| 42 void DecoderStreamTraits<DemuxerStream::AUDIO>::ReportStatistics( | 49 void DecoderStreamTraits<DemuxerStream::AUDIO>::ReportStatistics( |
| 43 const StatisticsCB& statistics_cb, | 50 const StatisticsCB& statistics_cb, |
| 44 int bytes_decoded) { | 51 int bytes_decoded) { |
| 45 PipelineStatistics statistics; | 52 PipelineStatistics statistics; |
| 46 statistics.audio_bytes_decoded = bytes_decoded; | 53 statistics.audio_bytes_decoded = bytes_decoded; |
| 47 statistics_cb.Run(statistics); | 54 statistics_cb.Run(statistics); |
| 48 } | 55 } |
| 49 | 56 |
| 50 void DecoderStreamTraits<DemuxerStream::AUDIO>::InitializeDecoder( | 57 void DecoderStreamTraits<DemuxerStream::AUDIO>::InitializeDecoder( |
| 51 DecoderType* decoder, | 58 DecoderType* decoder, |
| 52 DemuxerStream* stream, | 59 const DecoderConfigType& config, |
| 60 bool /* low_delay */, |
| 53 CdmContext* cdm_context, | 61 CdmContext* cdm_context, |
| 54 const InitCB& init_cb, | 62 const InitCB& init_cb, |
| 55 const OutputCB& output_cb) { | 63 const OutputCB& output_cb) { |
| 56 DCHECK(stream->audio_decoder_config().IsValidConfig()); | 64 DCHECK(config.IsValidConfig()); |
| 57 decoder->Initialize(stream->audio_decoder_config(), cdm_context, init_cb, | 65 decoder->Initialize(config, cdm_context, init_cb, output_cb); |
| 58 output_cb); | |
| 59 } | 66 } |
| 60 | 67 |
| 61 void DecoderStreamTraits<DemuxerStream::AUDIO>::OnStreamReset( | 68 void DecoderStreamTraits<DemuxerStream::AUDIO>::OnStreamReset( |
| 62 DemuxerStream* stream) { | 69 DemuxerStream* stream) { |
| 63 DCHECK(stream); | 70 DCHECK(stream); |
| 64 // Stream is likely being seeked to a new timestamp, so make new validator to | 71 // Stream is likely being seeked to a new timestamp, so make new validator to |
| 65 // build new timestamp expectations. | 72 // build new timestamp expectations. |
| 66 audio_ts_validator_.reset( | 73 audio_ts_validator_.reset( |
| 67 new AudioTimestampValidator(stream->audio_decoder_config(), media_log_)); | 74 new AudioTimestampValidator(stream->audio_decoder_config(), media_log_)); |
| 68 } | 75 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 89 DecoderType* decoder) { | 96 DecoderType* decoder) { |
| 90 return decoder->NeedsBitstreamConversion(); | 97 return decoder->NeedsBitstreamConversion(); |
| 91 } | 98 } |
| 92 | 99 |
| 93 // static | 100 // static |
| 94 scoped_refptr<DecoderStreamTraits<DemuxerStream::VIDEO>::OutputType> | 101 scoped_refptr<DecoderStreamTraits<DemuxerStream::VIDEO>::OutputType> |
| 95 DecoderStreamTraits<DemuxerStream::VIDEO>::CreateEOSOutput() { | 102 DecoderStreamTraits<DemuxerStream::VIDEO>::CreateEOSOutput() { |
| 96 return OutputType::CreateEOSFrame(); | 103 return OutputType::CreateEOSFrame(); |
| 97 } | 104 } |
| 98 | 105 |
| 106 // static |
| 107 DecoderStreamTraits<DemuxerStream::VIDEO>::DecoderConfigType |
| 108 DecoderStreamTraits<DemuxerStream::VIDEO>::GetDecoderConfig( |
| 109 DemuxerStream* stream) { |
| 110 return stream->video_decoder_config(); |
| 111 } |
| 112 |
| 99 DecoderStreamTraits<DemuxerStream::VIDEO>::DecoderStreamTraits( | 113 DecoderStreamTraits<DemuxerStream::VIDEO>::DecoderStreamTraits( |
| 100 const scoped_refptr<MediaLog>& media_log) | 114 const scoped_refptr<MediaLog>& media_log) |
| 101 // Randomly selected number of samples to keep. | 115 // Randomly selected number of samples to keep. |
| 102 : keyframe_distance_average_(16) {} | 116 : keyframe_distance_average_(16) {} |
| 103 | 117 |
| 104 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( | 118 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( |
| 105 const StatisticsCB& statistics_cb, | 119 const StatisticsCB& statistics_cb, |
| 106 int bytes_decoded) { | 120 int bytes_decoded) { |
| 107 PipelineStatistics statistics; | 121 PipelineStatistics statistics; |
| 108 statistics.video_bytes_decoded = bytes_decoded; | 122 statistics.video_bytes_decoded = bytes_decoded; |
| 109 | 123 |
| 110 if (keyframe_distance_average_.count()) { | 124 if (keyframe_distance_average_.count()) { |
| 111 statistics.video_keyframe_distance_average = | 125 statistics.video_keyframe_distance_average = |
| 112 keyframe_distance_average_.Average(); | 126 keyframe_distance_average_.Average(); |
| 113 } else { | 127 } else { |
| 114 // Before we have enough keyframes to calculate the average distance, we | 128 // Before we have enough keyframes to calculate the average distance, we |
| 115 // will assume the average keyframe distance is infinitely large. | 129 // will assume the average keyframe distance is infinitely large. |
| 116 statistics.video_keyframe_distance_average = base::TimeDelta::Max(); | 130 statistics.video_keyframe_distance_average = base::TimeDelta::Max(); |
| 117 } | 131 } |
| 118 | 132 |
| 119 statistics_cb.Run(statistics); | 133 statistics_cb.Run(statistics); |
| 120 } | 134 } |
| 121 | 135 |
| 122 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( | 136 void DecoderStreamTraits<DemuxerStream::VIDEO>::InitializeDecoder( |
| 123 DecoderType* decoder, | 137 DecoderType* decoder, |
| 124 DemuxerStream* stream, | 138 const DecoderConfigType& config, |
| 139 bool low_delay, |
| 125 CdmContext* cdm_context, | 140 CdmContext* cdm_context, |
| 126 const InitCB& init_cb, | 141 const InitCB& init_cb, |
| 127 const OutputCB& output_cb) { | 142 const OutputCB& output_cb) { |
| 128 DCHECK(stream->video_decoder_config().IsValidConfig()); | 143 DCHECK(config.IsValidConfig()); |
| 129 decoder->Initialize(stream->video_decoder_config(), | 144 decoder->Initialize(config, low_delay, cdm_context, init_cb, output_cb); |
| 130 stream->liveness() == DemuxerStream::LIVENESS_LIVE, | |
| 131 cdm_context, init_cb, output_cb); | |
| 132 } | 145 } |
| 133 | 146 |
| 134 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnStreamReset( | 147 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnStreamReset( |
| 135 DemuxerStream* stream) { | 148 DemuxerStream* stream) { |
| 136 DCHECK(stream); | 149 DCHECK(stream); |
| 137 last_keyframe_timestamp_ = base::TimeDelta(); | 150 last_keyframe_timestamp_ = base::TimeDelta(); |
| 138 } | 151 } |
| 139 | 152 |
| 140 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnDecode( | 153 void DecoderStreamTraits<DemuxerStream::VIDEO>::OnDecode( |
| 141 const scoped_refptr<DecoderBuffer>& buffer) { | 154 const scoped_refptr<DecoderBuffer>& buffer) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 } | 170 } |
| 158 | 171 |
| 159 base::TimeDelta frame_distance = | 172 base::TimeDelta frame_distance = |
| 160 current_frame_timestamp - last_keyframe_timestamp_; | 173 current_frame_timestamp - last_keyframe_timestamp_; |
| 161 UMA_HISTOGRAM_MEDIUM_TIMES("Media.Video.KeyFrameDistance", frame_distance); | 174 UMA_HISTOGRAM_MEDIUM_TIMES("Media.Video.KeyFrameDistance", frame_distance); |
| 162 last_keyframe_timestamp_ = current_frame_timestamp; | 175 last_keyframe_timestamp_ = current_frame_timestamp; |
| 163 keyframe_distance_average_.AddSample(frame_distance); | 176 keyframe_distance_average_.AddSample(frame_distance); |
| 164 } | 177 } |
| 165 | 178 |
| 166 } // namespace media | 179 } // namespace media |
| OLD | NEW |