| 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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "media/base/audio_decoder_config.h" | 11 #include "media/base/audio_decoder_config.h" |
| 12 #include "media/base/cdm_context.h" |
| 12 #include "media/base/decryptor.h" | 13 #include "media/base/decryptor.h" |
| 13 #include "media/base/demuxer_stream.h" | 14 #include "media/base/demuxer_stream.h" |
| 14 #include "media/base/pipeline_status.h" | 15 #include "media/base/pipeline_status.h" |
| 15 #include "media/base/video_decoder_config.h" | 16 #include "media/base/video_decoder_config.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 class DecoderBuffer; | 24 class DecoderBuffer; |
| 24 class MediaLog; | 25 class MediaLog; |
| 25 | 26 |
| 26 // Decryptor-based DemuxerStream implementation that converts a potentially | 27 // Decryptor-based DemuxerStream implementation that converts a potentially |
| 27 // encrypted demuxer stream to a clear demuxer stream. | 28 // encrypted demuxer stream to a clear demuxer stream. |
| 28 // All public APIs and callbacks are trampolined to the |task_runner_| so | 29 // All public APIs and callbacks are trampolined to the |task_runner_| so |
| 29 // that no locks are required for thread safety. | 30 // that no locks are required for thread safety. |
| 30 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { | 31 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { |
| 31 public: | 32 public: |
| 32 DecryptingDemuxerStream( | 33 DecryptingDemuxerStream( |
| 33 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 34 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 34 const scoped_refptr<MediaLog>& media_log, | 35 const scoped_refptr<MediaLog>& media_log, |
| 35 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 36 const SetCdmReadyCB& set_cdm_ready_cb, |
| 36 const base::Closure& waiting_for_decryption_key_cb); | 37 const base::Closure& waiting_for_decryption_key_cb); |
| 37 | 38 |
| 38 // Cancels all pending operations immediately and fires all pending callbacks. | 39 // Cancels all pending operations immediately and fires all pending callbacks. |
| 39 ~DecryptingDemuxerStream() override; | 40 ~DecryptingDemuxerStream() override; |
| 40 | 41 |
| 41 void Initialize(DemuxerStream* stream, | 42 void Initialize(DemuxerStream* stream, const PipelineStatusCB& status_cb); |
| 42 const PipelineStatusCB& status_cb); | |
| 43 | 43 |
| 44 // Cancels all pending operations and fires all pending callbacks. If in | 44 // Cancels all pending operations and fires all pending callbacks. If in |
| 45 // kPendingDemuxerRead or kPendingDecrypt state, waits for the pending | 45 // kPendingDemuxerRead or kPendingDecrypt state, waits for the pending |
| 46 // operation to finish before satisfying |closure|. Sets the state to | 46 // operation to finish before satisfying |closure|. Sets the state to |
| 47 // kUninitialized if |this| hasn't been initialized, or to kIdle otherwise. | 47 // kUninitialized if |this| hasn't been initialized, or to kIdle otherwise. |
| 48 void Reset(const base::Closure& closure); | 48 void Reset(const base::Closure& closure); |
| 49 | 49 |
| 50 // Returns the name of this class for logging purpose. | 50 // Returns the name of this class for logging purpose. |
| 51 std::string GetDisplayName() const; | 51 std::string GetDisplayName() const; |
| 52 | 52 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. | 67 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. |
| 68 enum State { | 68 enum State { |
| 69 kUninitialized = 0, | 69 kUninitialized = 0, |
| 70 kDecryptorRequested, | 70 kDecryptorRequested, |
| 71 kIdle, | 71 kIdle, |
| 72 kPendingDemuxerRead, | 72 kPendingDemuxerRead, |
| 73 kPendingDecrypt, | 73 kPendingDecrypt, |
| 74 kWaitingForKey | 74 kWaitingForKey |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // Callback for DecryptorHost::RequestDecryptor(). |decryptor_attached_cb| is | 77 // Callback to set CDM. |cdm_attached_cb| is called when the decryptor in the |
| 78 // called when the decryptor has been completely attached to the pipeline. | 78 // CDM has been completely attached to the pipeline. |
| 79 void SetDecryptor(Decryptor* decryptor, | 79 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); |
| 80 const DecryptorAttachedCB& decryptor_attached_cb); | |
| 81 | 80 |
| 82 // Callback for DemuxerStream::Read(). | 81 // Callback for DemuxerStream::Read(). |
| 83 void DecryptBuffer(DemuxerStream::Status status, | 82 void DecryptBuffer(DemuxerStream::Status status, |
| 84 const scoped_refptr<DecoderBuffer>& buffer); | 83 const scoped_refptr<DecoderBuffer>& buffer); |
| 85 | 84 |
| 86 void DecryptPendingBuffer(); | 85 void DecryptPendingBuffer(); |
| 87 | 86 |
| 88 // Callback for Decryptor::Decrypt(). | 87 // Callback for Decryptor::Decrypt(). |
| 89 void DeliverBuffer(Decryptor::Status status, | 88 void DeliverBuffer(Decryptor::Status status, |
| 90 const scoped_refptr<DecoderBuffer>& decrypted_buffer); | 89 const scoped_refptr<DecoderBuffer>& decrypted_buffer); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 113 ReadCB read_cb_; | 112 ReadCB read_cb_; |
| 114 base::Closure reset_cb_; | 113 base::Closure reset_cb_; |
| 115 base::Closure waiting_for_decryption_key_cb_; | 114 base::Closure waiting_for_decryption_key_cb_; |
| 116 | 115 |
| 117 // Pointer to the input demuxer stream that will feed us encrypted buffers. | 116 // Pointer to the input demuxer stream that will feed us encrypted buffers. |
| 118 DemuxerStream* demuxer_stream_; | 117 DemuxerStream* demuxer_stream_; |
| 119 | 118 |
| 120 AudioDecoderConfig audio_config_; | 119 AudioDecoderConfig audio_config_; |
| 121 VideoDecoderConfig video_config_; | 120 VideoDecoderConfig video_config_; |
| 122 | 121 |
| 123 // Callback to request/cancel decryptor creation notification. | 122 // Callback to request/cancel CDM ready notification. |
| 124 SetDecryptorReadyCB set_decryptor_ready_cb_; | 123 SetCdmReadyCB set_cdm_ready_cb_; |
| 125 | 124 |
| 126 Decryptor* decryptor_; | 125 Decryptor* decryptor_; |
| 127 | 126 |
| 128 // The buffer returned by the demuxer that needs to be decrypted. | 127 // The buffer returned by the demuxer that needs to be decrypted. |
| 129 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; | 128 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; |
| 130 | 129 |
| 131 // Indicates the situation where new key is added during pending decryption | 130 // Indicates the situation where new key is added during pending decryption |
| 132 // (in other words, this variable can only be set in state kPendingDecrypt). | 131 // (in other words, this variable can only be set in state kPendingDecrypt). |
| 133 // If this variable is true and kNoKey is returned then we need to try | 132 // If this variable is true and kNoKey is returned then we need to try |
| 134 // decrypting again in case the newly added key is the correct decryption key. | 133 // decrypting again in case the newly added key is the correct decryption key. |
| 135 bool key_added_while_decrypt_pending_; | 134 bool key_added_while_decrypt_pending_; |
| 136 | 135 |
| 137 base::WeakPtr<DecryptingDemuxerStream> weak_this_; | 136 base::WeakPtr<DecryptingDemuxerStream> weak_this_; |
| 138 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_; | 137 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_; |
| 139 | 138 |
| 140 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); | 139 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); |
| 141 }; | 140 }; |
| 142 | 141 |
| 143 } // namespace media | 142 } // namespace media |
| 144 | 143 |
| 145 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ | 144 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
| OLD | NEW |