| 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 #ifndef MEDIA_FILTERS_DECODER_STREAM_TRAITS_H_ | 5 #ifndef MEDIA_FILTERS_DECODER_STREAM_TRAITS_H_ |
| 6 #define MEDIA_FILTERS_DECODER_STREAM_TRAITS_H_ | 6 #define MEDIA_FILTERS_DECODER_STREAM_TRAITS_H_ |
| 7 | 7 |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "media/base/cdm_context.h" | 9 #include "media/base/cdm_context.h" |
| 10 #include "media/base/demuxer_stream.h" | 10 #include "media/base/demuxer_stream.h" |
| 11 #include "media/base/moving_average.h" | 11 #include "media/base/moving_average.h" |
| 12 #include "media/base/pipeline_status.h" | 12 #include "media/base/pipeline_status.h" |
| 13 #include "media/base/video_decoder_config.h" | 13 #include "media/base/video_decoder_config.h" |
| 14 #include "media/filters/audio_timestamp_validator.h" | 14 #include "media/filters/audio_timestamp_validator.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 class AudioBuffer; | 18 class AudioBuffer; |
| 19 class AudioDecoder; | 19 class AudioDecoder; |
| 20 class AudioDecoderConfig; |
| 20 class CdmContext; | 21 class CdmContext; |
| 21 class DecryptingAudioDecoder; | 22 class DecryptingAudioDecoder; |
| 22 class DecryptingVideoDecoder; | 23 class DecryptingVideoDecoder; |
| 23 class DemuxerStream; | 24 class DemuxerStream; |
| 24 class VideoDecoder; | 25 class VideoDecoder; |
| 26 class VideoDecoderConfig; |
| 25 class VideoFrame; | 27 class VideoFrame; |
| 26 | 28 |
| 27 template <DemuxerStream::Type StreamType> | 29 template <DemuxerStream::Type StreamType> |
| 28 class DecoderStreamTraits {}; | 30 class DecoderStreamTraits {}; |
| 29 | 31 |
| 30 template <> | 32 template <> |
| 31 class MEDIA_EXPORT DecoderStreamTraits<DemuxerStream::AUDIO> { | 33 class MEDIA_EXPORT DecoderStreamTraits<DemuxerStream::AUDIO> { |
| 32 public: | 34 public: |
| 33 typedef AudioBuffer OutputType; | 35 typedef AudioBuffer OutputType; |
| 34 typedef AudioDecoder DecoderType; | 36 typedef AudioDecoder DecoderType; |
| 37 typedef AudioDecoderConfig DecoderConfigType; |
| 35 typedef DecryptingAudioDecoder DecryptingDecoderType; | 38 typedef DecryptingAudioDecoder DecryptingDecoderType; |
| 36 typedef base::Callback<void(bool success)> InitCB; | 39 typedef base::Callback<void(bool success)> InitCB; |
| 37 typedef base::Callback<void(const scoped_refptr<OutputType>&)> OutputCB; | 40 typedef base::Callback<void(const scoped_refptr<OutputType>&)> OutputCB; |
| 38 | 41 |
| 39 static std::string ToString(); | 42 static std::string ToString(); |
| 40 static bool NeedsBitstreamConversion(DecoderType* decoder); | 43 static bool NeedsBitstreamConversion(DecoderType* decoder); |
| 41 static scoped_refptr<OutputType> CreateEOSOutput(); | 44 static scoped_refptr<OutputType> CreateEOSOutput(); |
| 45 static DecoderConfigType GetDecoderConfig(DemuxerStream* stream); |
| 42 | 46 |
| 43 explicit DecoderStreamTraits(const scoped_refptr<MediaLog>& media_log); | 47 explicit DecoderStreamTraits(const scoped_refptr<MediaLog>& media_log); |
| 44 | 48 |
| 45 void ReportStatistics(const StatisticsCB& statistics_cb, int bytes_decoded); | 49 void ReportStatistics(const StatisticsCB& statistics_cb, int bytes_decoded); |
| 46 void InitializeDecoder(DecoderType* decoder, | 50 void InitializeDecoder(DecoderType* decoder, |
| 47 DemuxerStream* stream, | 51 const DecoderConfigType& config, |
| 52 bool low_delay, |
| 48 CdmContext* cdm_context, | 53 CdmContext* cdm_context, |
| 49 const InitCB& init_cb, | 54 const InitCB& init_cb, |
| 50 const OutputCB& output_cb); | 55 const OutputCB& output_cb); |
| 51 void OnDecode(const scoped_refptr<DecoderBuffer>& buffer); | 56 void OnDecode(const scoped_refptr<DecoderBuffer>& buffer); |
| 52 void OnDecodeDone(const scoped_refptr<OutputType>& buffer); | 57 void OnDecodeDone(const scoped_refptr<OutputType>& buffer); |
| 53 void OnStreamReset(DemuxerStream* stream); | 58 void OnStreamReset(DemuxerStream* stream); |
| 54 | 59 |
| 55 private: | 60 private: |
| 56 // Validates encoded timestamps match decoded output duration. MEDIA_LOG warns | 61 // Validates encoded timestamps match decoded output duration. MEDIA_LOG warns |
| 57 // if timestamp gaps are detected. Sufficiently large gaps can lead to AV sync | 62 // if timestamp gaps are detected. Sufficiently large gaps can lead to AV sync |
| 58 // drift. | 63 // drift. |
| 59 std::unique_ptr<AudioTimestampValidator> audio_ts_validator_; | 64 std::unique_ptr<AudioTimestampValidator> audio_ts_validator_; |
| 60 | 65 |
| 61 scoped_refptr<MediaLog> media_log_; | 66 scoped_refptr<MediaLog> media_log_; |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 template <> | 69 template <> |
| 65 class MEDIA_EXPORT DecoderStreamTraits<DemuxerStream::VIDEO> { | 70 class MEDIA_EXPORT DecoderStreamTraits<DemuxerStream::VIDEO> { |
| 66 public: | 71 public: |
| 67 typedef VideoFrame OutputType; | 72 typedef VideoFrame OutputType; |
| 68 typedef VideoDecoder DecoderType; | 73 typedef VideoDecoder DecoderType; |
| 74 typedef VideoDecoderConfig DecoderConfigType; |
| 69 typedef DecryptingVideoDecoder DecryptingDecoderType; | 75 typedef DecryptingVideoDecoder DecryptingDecoderType; |
| 70 typedef base::Callback<void(bool success)> InitCB; | 76 typedef base::Callback<void(bool success)> InitCB; |
| 71 typedef base::Callback<void(const scoped_refptr<OutputType>&)> OutputCB; | 77 typedef base::Callback<void(const scoped_refptr<OutputType>&)> OutputCB; |
| 72 | 78 |
| 73 static std::string ToString(); | 79 static std::string ToString(); |
| 74 static bool NeedsBitstreamConversion(DecoderType* decoder); | 80 static bool NeedsBitstreamConversion(DecoderType* decoder); |
| 75 static scoped_refptr<OutputType> CreateEOSOutput(); | 81 static scoped_refptr<OutputType> CreateEOSOutput(); |
| 82 static DecoderConfigType GetDecoderConfig(DemuxerStream* stream); |
| 76 | 83 |
| 77 explicit DecoderStreamTraits(const scoped_refptr<MediaLog>& media_log); | 84 explicit DecoderStreamTraits(const scoped_refptr<MediaLog>& media_log); |
| 78 | 85 |
| 79 void ReportStatistics(const StatisticsCB& statistics_cb, int bytes_decoded); | 86 void ReportStatistics(const StatisticsCB& statistics_cb, int bytes_decoded); |
| 80 void InitializeDecoder(DecoderType* decoder, | 87 void InitializeDecoder(DecoderType* decoder, |
| 81 DemuxerStream* stream, | 88 const DecoderConfigType& config, |
| 89 bool low_delay, |
| 82 CdmContext* cdm_context, | 90 CdmContext* cdm_context, |
| 83 const InitCB& init_cb, | 91 const InitCB& init_cb, |
| 84 const OutputCB& output_cb); | 92 const OutputCB& output_cb); |
| 85 void OnDecode(const scoped_refptr<DecoderBuffer>& buffer); | 93 void OnDecode(const scoped_refptr<DecoderBuffer>& buffer); |
| 86 void OnDecodeDone(const scoped_refptr<OutputType>& buffer) {} | 94 void OnDecodeDone(const scoped_refptr<OutputType>& buffer) {} |
| 87 void OnStreamReset(DemuxerStream* stream); | 95 void OnStreamReset(DemuxerStream* stream); |
| 88 | 96 |
| 89 private: | 97 private: |
| 90 base::TimeDelta last_keyframe_timestamp_; | 98 base::TimeDelta last_keyframe_timestamp_; |
| 91 MovingAverage keyframe_distance_average_; | 99 MovingAverage keyframe_distance_average_; |
| 92 }; | 100 }; |
| 93 | 101 |
| 94 } // namespace media | 102 } // namespace media |
| 95 | 103 |
| 96 #endif // MEDIA_FILTERS_DECODER_STREAM_TRAITS_H_ | 104 #endif // MEDIA_FILTERS_DECODER_STREAM_TRAITS_H_ |
| OLD | NEW |