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 26 matching lines...) Expand all Loading... |
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(const AudioDecoderConfig& config, | 46 virtual void Initialize(const AudioDecoderConfig& config, |
47 const PipelineStatusCB& status_cb) OVERRIDE; | 47 const PipelineStatusCB& status_cb, |
| 48 const OutputCB& output_cb) OVERRIDE; |
48 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 49 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
49 const DecodeCB& decode_cb) OVERRIDE; | 50 const DecodeCB& decode_cb) OVERRIDE; |
50 virtual scoped_refptr<AudioBuffer> GetDecodeOutput() OVERRIDE; | |
51 virtual void Reset(const base::Closure& closure) OVERRIDE; | 51 virtual void Reset(const base::Closure& closure) OVERRIDE; |
52 virtual void Stop() OVERRIDE; | 52 virtual void Stop() OVERRIDE; |
53 | 53 |
54 private: | 54 private: |
55 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 55 // For a detailed state diagram please see this link: http://goo.gl/8jAok |
56 // TODO(xhwang): Add a ASCII state diagram in this file after this class | 56 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
57 // stabilizes. | 57 // stabilizes. |
58 // TODO(xhwang): Update this diagram for DecryptingAudioDecoder. | 58 // TODO(xhwang): Update this diagram for DecryptingAudioDecoder. |
59 enum State { | 59 enum State { |
60 kUninitialized = 0, | 60 kUninitialized = 0, |
(...skipping 22 matching lines...) Expand all Loading... |
83 Decryptor::Status status, | 83 Decryptor::Status status, |
84 const Decryptor::AudioBuffers& frames); | 84 const Decryptor::AudioBuffers& frames); |
85 | 85 |
86 // Callback for the |decryptor_| to notify this object that a new key has been | 86 // Callback for the |decryptor_| to notify this object that a new key has been |
87 // added. | 87 // added. |
88 void OnKeyAdded(); | 88 void OnKeyAdded(); |
89 | 89 |
90 // Resets decoder and calls |reset_cb_|. | 90 // Resets decoder and calls |reset_cb_|. |
91 void DoReset(); | 91 void DoReset(); |
92 | 92 |
93 // Sets timestamp and duration for |queued_audio_frames_| to make sure the | 93 // Sets timestamps for |frames| and then passes them to |output_cb_|. |
94 // renderer always receives continuous frames without gaps and overlaps. | 94 void ProcessDecodedFrames(const Decryptor::AudioBuffers& frames); |
95 void EnqueueFrames(const Decryptor::AudioBuffers& frames); | |
96 | 95 |
97 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 96 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
98 | 97 |
99 State state_; | 98 State state_; |
100 | 99 |
101 PipelineStatusCB init_cb_; | 100 PipelineStatusCB init_cb_; |
| 101 OutputCB output_cb_; |
102 DecodeCB decode_cb_; | 102 DecodeCB decode_cb_; |
103 base::Closure reset_cb_; | 103 base::Closure reset_cb_; |
104 base::Closure stop_cb_; | 104 base::Closure stop_cb_; |
105 | 105 |
106 // The current decoder configuration. | 106 // The current decoder configuration. |
107 AudioDecoderConfig config_; | 107 AudioDecoderConfig config_; |
108 | 108 |
109 // Callback to request/cancel decryptor creation notification. | 109 // Callback to request/cancel decryptor creation notification. |
110 SetDecryptorReadyCB set_decryptor_ready_cb_; | 110 SetDecryptorReadyCB set_decryptor_ready_cb_; |
111 | 111 |
112 Decryptor* decryptor_; | 112 Decryptor* decryptor_; |
113 | 113 |
114 // The buffer that needs decrypting/decoding. | 114 // The buffer that needs decrypting/decoding. |
115 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; | 115 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; |
116 | 116 |
117 // Indicates the situation where new key is added during pending decode | 117 // Indicates the situation where new key is added during pending decode |
118 // (in other words, this variable can only be set in state kPendingDecode). | 118 // (in other words, this variable can only be set in state kPendingDecode). |
119 // If this variable is true and kNoKey is returned then we need to try | 119 // If this variable is true and kNoKey is returned then we need to try |
120 // decrypting/decoding again in case the newly added key is the correct | 120 // decrypting/decoding again in case the newly added key is the correct |
121 // decryption key. | 121 // decryption key. |
122 bool key_added_while_decode_pending_; | 122 bool key_added_while_decode_pending_; |
123 | 123 |
124 Decryptor::AudioBuffers queued_audio_frames_; | |
125 | |
126 scoped_ptr<AudioTimestampHelper> timestamp_helper_; | 124 scoped_ptr<AudioTimestampHelper> timestamp_helper_; |
127 | 125 |
128 // NOTE: Weak pointers must be invalidated before all other member variables. | 126 // NOTE: Weak pointers must be invalidated before all other member variables. |
129 base::WeakPtrFactory<DecryptingAudioDecoder> weak_factory_; | 127 base::WeakPtrFactory<DecryptingAudioDecoder> weak_factory_; |
130 base::WeakPtr<DecryptingAudioDecoder> weak_this_; | 128 base::WeakPtr<DecryptingAudioDecoder> weak_this_; |
131 | 129 |
132 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoder); | 130 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoder); |
133 }; | 131 }; |
134 | 132 |
135 } // namespace media | 133 } // namespace media |
136 | 134 |
137 #endif // MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ | 135 #endif // MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
OLD | NEW |