OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_DECRYPTING_AUDIO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
6 #define MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ | 6 #define MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 // format designated by kSupportedBitsPerChannel. | 36 // format designated by kSupportedBitsPerChannel. |
37 // TODO(xhwang): Remove this restriction after http://crbug.com/169105 fixed. | 37 // TODO(xhwang): Remove this restriction after http://crbug.com/169105 fixed. |
38 static const int kSupportedBitsPerChannel; | 38 static const int kSupportedBitsPerChannel; |
39 | 39 |
40 DecryptingAudioDecoder( | 40 DecryptingAudioDecoder( |
41 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 41 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
42 const SetDecryptorReadyCB& set_decryptor_ready_cb); | 42 const SetDecryptorReadyCB& set_decryptor_ready_cb); |
43 virtual ~DecryptingAudioDecoder(); | 43 virtual ~DecryptingAudioDecoder(); |
44 | 44 |
45 // AudioDecoder implementation. | 45 // AudioDecoder implementation. |
46 virtual void Initialize(DemuxerStream* stream, | 46 virtual void Initialize(const AudioDecoderConfig& config, |
47 const PipelineStatusCB& status_cb, | 47 const PipelineStatusCB& status_cb) OVERRIDE; |
48 const StatisticsCB& statistics_cb) OVERRIDE; | 48 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
49 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 49 const DecodeCB& decode_cb) OVERRIDE; |
| 50 virtual scoped_refptr<AudioBuffer> GetDecodeOutput() OVERRIDE; |
50 virtual void Reset(const base::Closure& closure) OVERRIDE; | 51 virtual void Reset(const base::Closure& closure) OVERRIDE; |
51 virtual void Stop(const base::Closure& closure) OVERRIDE; | 52 virtual void Stop(const base::Closure& closure) OVERRIDE; |
52 virtual int bits_per_channel() OVERRIDE; | 53 virtual int bits_per_channel() OVERRIDE; |
53 virtual ChannelLayout channel_layout() OVERRIDE; | 54 virtual ChannelLayout channel_layout() OVERRIDE; |
54 virtual int samples_per_second() OVERRIDE; | 55 virtual int samples_per_second() OVERRIDE; |
55 | 56 |
56 private: | 57 private: |
57 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 58 // For a detailed state diagram please see this link: http://goo.gl/8jAok |
58 // TODO(xhwang): Add a ASCII state diagram in this file after this class | 59 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
59 // stabilizes. | 60 // stabilizes. |
60 // TODO(xhwang): Update this diagram for DecryptingAudioDecoder. | 61 // TODO(xhwang): Update this diagram for DecryptingAudioDecoder. |
61 enum State { | 62 enum State { |
62 kUninitialized = 0, | 63 kUninitialized = 0, |
63 kDecryptorRequested, | 64 kDecryptorRequested, |
64 kPendingDecoderInit, | 65 kPendingDecoderInit, |
65 kIdle, | 66 kIdle, |
66 kPendingConfigChange, | 67 kPendingConfigChange, |
67 kPendingDemuxerRead, | |
68 kPendingDecode, | 68 kPendingDecode, |
69 kWaitingForKey, | 69 kWaitingForKey, |
70 kDecodeFinished, | 70 kDecodeFinished, |
71 kStopped, | 71 kStopped, |
72 }; | 72 }; |
73 | 73 |
74 // Callback for DecryptorHost::RequestDecryptor(). | 74 // Callback for DecryptorHost::RequestDecryptor(). |
75 void SetDecryptor(Decryptor* decryptor); | 75 void SetDecryptor(Decryptor* decryptor); |
76 | 76 |
77 // Callback for Decryptor::InitializeAudioDecoder() during initialization. | 77 // Callback for Decryptor::InitializeAudioDecoder() during initialization. |
78 void FinishInitialization(bool success); | 78 void FinishInitialization(bool success); |
79 | 79 |
80 // Callback for Decryptor::InitializeAudioDecoder() during config change. | |
81 void FinishConfigChange(bool success); | |
82 | |
83 // Reads from the demuxer stream with corresponding callback method. | |
84 void ReadFromDemuxerStream(); | |
85 void DecryptAndDecodeBuffer(DemuxerStream::Status status, | |
86 const scoped_refptr<DecoderBuffer>& buffer); | |
87 | |
88 void DecodePendingBuffer(); | 80 void DecodePendingBuffer(); |
89 | 81 |
90 // Callback for Decryptor::DecryptAndDecodeAudio(). | 82 // Callback for Decryptor::DecryptAndDecodeAudio(). |
91 void DeliverFrame(int buffer_size, | 83 void DeliverFrame(int buffer_size, |
92 Decryptor::Status status, | 84 Decryptor::Status status, |
93 const Decryptor::AudioBuffers& frames); | 85 const Decryptor::AudioBuffers& frames); |
94 | 86 |
95 // Callback for the |decryptor_| to notify this object that a new key has been | 87 // Callback for the |decryptor_| to notify this object that a new key has been |
96 // added. | 88 // added. |
97 void OnKeyAdded(); | 89 void OnKeyAdded(); |
98 | 90 |
99 // Resets decoder and calls |reset_cb_|. | 91 // Resets decoder and calls |reset_cb_|. |
100 void DoReset(); | 92 void DoReset(); |
101 | 93 |
102 // Updates audio configs from |demuxer_stream_| and resets | 94 // Updates audio configs from |demuxer_stream_| and resets |
103 // |output_timestamp_base_| and |total_samples_decoded_|. | 95 // |output_timestamp_base_| and |total_samples_decoded_|. |
104 void UpdateDecoderConfig(); | 96 void UpdateDecoderConfig(); |
105 | 97 |
106 // Sets timestamp and duration for |queued_audio_frames_| to make sure the | 98 // Sets timestamp and duration for |queued_audio_frames_| to make sure the |
107 // renderer always receives continuous frames without gaps and overlaps. | 99 // renderer always receives continuous frames without gaps and overlaps. |
108 void EnqueueFrames(const Decryptor::AudioBuffers& frames); | 100 void EnqueueFrames(const Decryptor::AudioBuffers& frames); |
109 | 101 |
110 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 102 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
111 base::WeakPtrFactory<DecryptingAudioDecoder> weak_factory_; | 103 base::WeakPtrFactory<DecryptingAudioDecoder> weak_factory_; |
112 base::WeakPtr<DecryptingAudioDecoder> weak_this_; | 104 base::WeakPtr<DecryptingAudioDecoder> weak_this_; |
113 | 105 |
114 State state_; | 106 State state_; |
115 | 107 |
116 PipelineStatusCB init_cb_; | 108 PipelineStatusCB init_cb_; |
117 StatisticsCB statistics_cb_; | 109 DecodeCB decode_cb_; |
118 ReadCB read_cb_; | |
119 base::Closure reset_cb_; | 110 base::Closure reset_cb_; |
120 base::Closure stop_cb_; | 111 base::Closure stop_cb_; |
121 | 112 |
122 // Pointer to the demuxer stream that will feed us compressed buffers. | 113 // The current decoder configuration. |
123 DemuxerStream* demuxer_stream_; | 114 AudioDecoderConfig config_; |
124 | 115 |
125 // Callback to request/cancel decryptor creation notification. | 116 // Callback to request/cancel decryptor creation notification. |
126 SetDecryptorReadyCB set_decryptor_ready_cb_; | 117 SetDecryptorReadyCB set_decryptor_ready_cb_; |
127 | 118 |
128 Decryptor* decryptor_; | 119 Decryptor* decryptor_; |
129 | 120 |
130 // The buffer returned by the demuxer that needs decrypting/decoding. | 121 // The buffer that needs decrypting/decoding. |
131 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; | 122 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; |
132 | 123 |
133 // Indicates the situation where new key is added during pending decode | 124 // Indicates the situation where new key is added during pending decode |
134 // (in other words, this variable can only be set in state kPendingDecode). | 125 // (in other words, this variable can only be set in state kPendingDecode). |
135 // If this variable is true and kNoKey is returned then we need to try | 126 // If this variable is true and kNoKey is returned then we need to try |
136 // decrypting/decoding again in case the newly added key is the correct | 127 // decrypting/decoding again in case the newly added key is the correct |
137 // decryption key. | 128 // decryption key. |
138 bool key_added_while_decode_pending_; | 129 bool key_added_while_decode_pending_; |
139 | 130 |
140 Decryptor::AudioBuffers queued_audio_frames_; | 131 Decryptor::AudioBuffers queued_audio_frames_; |
141 | 132 |
142 // Decoded audio format. | 133 // Decoded audio format. |
143 int bits_per_channel_; | 134 int bits_per_channel_; |
144 ChannelLayout channel_layout_; | 135 ChannelLayout channel_layout_; |
145 int samples_per_second_; | 136 int samples_per_second_; |
146 | 137 |
147 scoped_ptr<AudioTimestampHelper> timestamp_helper_; | 138 scoped_ptr<AudioTimestampHelper> timestamp_helper_; |
148 | 139 |
149 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoder); | 140 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoder); |
150 }; | 141 }; |
151 | 142 |
152 } // namespace media | 143 } // namespace media |
153 | 144 |
154 #endif // MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ | 145 #endif // MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
OLD | NEW |