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_DEMUXER_STREAM_H_ | 5 #ifndef MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
6 #define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ | 6 #define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 public: | 33 public: |
34 DecryptingDemuxerStream( | 34 DecryptingDemuxerStream( |
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
36 const scoped_refptr<MediaLog>& media_log, | 36 const scoped_refptr<MediaLog>& media_log, |
37 const base::Closure& waiting_for_decryption_key_cb); | 37 const base::Closure& waiting_for_decryption_key_cb); |
38 | 38 |
39 // Cancels all pending operations immediately and fires all pending callbacks. | 39 // Cancels all pending operations immediately and fires all pending callbacks. |
40 ~DecryptingDemuxerStream() override; | 40 ~DecryptingDemuxerStream() override; |
41 | 41 |
42 void Initialize(DemuxerStream* stream, | 42 void Initialize(DemuxerStream* stream, |
43 const SetCdmReadyCB& set_cdm_ready_cb, | 43 CdmContext* cdm_context, |
44 const PipelineStatusCB& status_cb); | 44 const PipelineStatusCB& status_cb); |
45 | 45 |
46 // Cancels all pending operations and fires all pending callbacks. If in | 46 // Cancels all pending operations and fires all pending callbacks. If in |
47 // kPendingDemuxerRead or kPendingDecrypt state, waits for the pending | 47 // kPendingDemuxerRead or kPendingDecrypt state, waits for the pending |
48 // operation to finish before satisfying |closure|. Sets the state to | 48 // operation to finish before satisfying |closure|. Sets the state to |
49 // kUninitialized if |this| hasn't been initialized, or to kIdle otherwise. | 49 // kUninitialized if |this| hasn't been initialized, or to kIdle otherwise. |
50 void Reset(const base::Closure& closure); | 50 void Reset(const base::Closure& closure); |
51 | 51 |
52 // Returns the name of this class for logging purpose. | 52 // Returns the name of this class for logging purpose. |
53 std::string GetDisplayName() const; | 53 std::string GetDisplayName() const; |
54 | 54 |
55 // DemuxerStream implementation. | 55 // DemuxerStream implementation. |
56 void Read(const ReadCB& read_cb) override; | 56 void Read(const ReadCB& read_cb) override; |
57 AudioDecoderConfig audio_decoder_config() override; | 57 AudioDecoderConfig audio_decoder_config() override; |
58 VideoDecoderConfig video_decoder_config() override; | 58 VideoDecoderConfig video_decoder_config() override; |
59 Type type() const override; | 59 Type type() const override; |
60 Liveness liveness() const override; | 60 Liveness liveness() const override; |
61 void EnableBitstreamConverter() override; | 61 void EnableBitstreamConverter() override; |
62 bool SupportsConfigChanges() override; | 62 bool SupportsConfigChanges() override; |
63 VideoRotation video_rotation() override; | 63 VideoRotation video_rotation() override; |
64 | 64 |
65 private: | 65 private: |
66 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 66 // For a detailed state diagram please see this link: http://goo.gl/8jAok |
67 // TODO(xhwang): Add a ASCII state diagram in this file after this class | 67 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
68 // stabilizes. | 68 // stabilizes. |
69 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. | 69 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. |
70 enum State { | 70 enum State { |
71 kUninitialized = 0, | 71 kUninitialized = 0, |
72 kDecryptorRequested, | |
73 kIdle, | 72 kIdle, |
74 kPendingDemuxerRead, | 73 kPendingDemuxerRead, |
75 kPendingDecrypt, | 74 kPendingDecrypt, |
76 kWaitingForKey | 75 kWaitingForKey |
77 }; | 76 }; |
78 | 77 |
79 // Callback to set CDM. |cdm_attached_cb| is called when the decryptor in the | |
80 // CDM has been completely attached to the pipeline. | |
81 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); | |
82 | |
83 // Callback for DemuxerStream::Read(). | 78 // Callback for DemuxerStream::Read(). |
84 void DecryptBuffer(DemuxerStream::Status status, | 79 void DecryptBuffer(DemuxerStream::Status status, |
85 const scoped_refptr<DecoderBuffer>& buffer); | 80 const scoped_refptr<DecoderBuffer>& buffer); |
86 | 81 |
87 void DecryptPendingBuffer(); | 82 void DecryptPendingBuffer(); |
88 | 83 |
89 // Callback for Decryptor::Decrypt(). | 84 // Callback for Decryptor::Decrypt(). |
90 void DeliverBuffer(Decryptor::Status status, | 85 void DeliverBuffer(Decryptor::Status status, |
91 const scoped_refptr<DecoderBuffer>& decrypted_buffer); | 86 const scoped_refptr<DecoderBuffer>& decrypted_buffer); |
92 | 87 |
(...skipping 21 matching lines...) Expand all Loading... |
114 ReadCB read_cb_; | 109 ReadCB read_cb_; |
115 base::Closure reset_cb_; | 110 base::Closure reset_cb_; |
116 base::Closure waiting_for_decryption_key_cb_; | 111 base::Closure waiting_for_decryption_key_cb_; |
117 | 112 |
118 // Pointer to the input demuxer stream that will feed us encrypted buffers. | 113 // Pointer to the input demuxer stream that will feed us encrypted buffers. |
119 DemuxerStream* demuxer_stream_; | 114 DemuxerStream* demuxer_stream_; |
120 | 115 |
121 AudioDecoderConfig audio_config_; | 116 AudioDecoderConfig audio_config_; |
122 VideoDecoderConfig video_config_; | 117 VideoDecoderConfig video_config_; |
123 | 118 |
124 // Callback to request/cancel CDM ready notification. | |
125 SetCdmReadyCB set_cdm_ready_cb_; | |
126 | |
127 Decryptor* decryptor_; | 119 Decryptor* decryptor_; |
128 | 120 |
129 // The buffer returned by the demuxer that needs to be decrypted. | 121 // The buffer returned by the demuxer that needs to be decrypted. |
130 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; | 122 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; |
131 | 123 |
132 // Indicates the situation where new key is added during pending decryption | 124 // Indicates the situation where new key is added during pending decryption |
133 // (in other words, this variable can only be set in state kPendingDecrypt). | 125 // (in other words, this variable can only be set in state kPendingDecrypt). |
134 // 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 |
135 // decrypting again in case the newly added key is the correct decryption key. | 127 // decrypting again in case the newly added key is the correct decryption key. |
136 bool key_added_while_decrypt_pending_; | 128 bool key_added_while_decrypt_pending_; |
137 | 129 |
138 base::WeakPtr<DecryptingDemuxerStream> weak_this_; | 130 base::WeakPtr<DecryptingDemuxerStream> weak_this_; |
139 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_; | 131 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_; |
140 | 132 |
141 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); | 133 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); |
142 }; | 134 }; |
143 | 135 |
144 } // namespace media | 136 } // namespace media |
145 | 137 |
146 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ | 138 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
OLD | NEW |