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