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