| 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 "media/base/decryptor.h" | 11 #include "media/base/decryptor.h" |
| 11 #include "media/base/demuxer_stream.h" | 12 #include "media/base/demuxer_stream.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 class MessageLoopProxy; | 15 class MessageLoopProxy; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace media { | 18 namespace media { |
| 18 | 19 |
| 19 class DecoderBuffer; | 20 class DecoderBuffer; |
| 20 | 21 |
| 21 // Decryptor-based DemuxerStream implementation that converts a potentially | 22 // Decryptor-based DemuxerStream implementation that converts a potentially |
| 22 // encrypted demuxer stream to a clear demuxer stream. | 23 // encrypted demuxer stream to a clear demuxer stream. |
| 23 // All public APIs and callbacks are trampolined to the |message_loop_| so | 24 // All public APIs and callbacks are trampolined to the |message_loop_| so |
| 24 // that no locks are required for thread safety. | 25 // that no locks are required for thread safety. |
| 25 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { | 26 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { |
| 26 public: | 27 public: |
| 27 DecryptingDemuxerStream( | 28 DecryptingDemuxerStream( |
| 28 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 29 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 29 const SetDecryptorReadyCB& set_decryptor_ready_cb); | 30 const SetDecryptorReadyCB& set_decryptor_ready_cb); |
| 31 virtual ~DecryptingDemuxerStream(); |
| 30 | 32 |
| 31 void Initialize(const scoped_refptr<DemuxerStream>& stream, | 33 void Initialize(DemuxerStream* stream, |
| 32 const PipelineStatusCB& status_cb); | 34 const PipelineStatusCB& status_cb); |
| 33 void Reset(const base::Closure& closure); | 35 void Reset(const base::Closure& closure); |
| 34 | 36 |
| 35 // DemuxerStream implementation. | 37 // DemuxerStream implementation. |
| 36 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 38 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| 37 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; | 39 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; |
| 38 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; | 40 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; |
| 39 virtual Type type() OVERRIDE; | 41 virtual Type type() OVERRIDE; |
| 40 virtual void EnableBitstreamConverter() OVERRIDE; | 42 virtual void EnableBitstreamConverter() OVERRIDE; |
| 41 | 43 |
| 42 protected: | |
| 43 virtual ~DecryptingDemuxerStream(); | |
| 44 | |
| 45 private: | 44 private: |
| 46 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 45 // For a detailed state diagram please see this link: http://goo.gl/8jAok |
| 47 // TODO(xhwang): Add a ASCII state diagram in this file after this class | 46 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
| 48 // stabilizes. | 47 // stabilizes. |
| 49 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. | 48 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. |
| 50 enum State { | 49 enum State { |
| 51 kUninitialized = 0, | 50 kUninitialized = 0, |
| 52 kDecryptorRequested, | 51 kDecryptorRequested, |
| 53 kIdle, | 52 kIdle, |
| 54 kPendingDemuxerRead, | 53 kPendingDemuxerRead, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 77 void DoReset(); | 76 void DoReset(); |
| 78 | 77 |
| 79 // Returns Decryptor::StreamType converted from |stream_type_|. | 78 // Returns Decryptor::StreamType converted from |stream_type_|. |
| 80 Decryptor::StreamType GetDecryptorStreamType() const; | 79 Decryptor::StreamType GetDecryptorStreamType() const; |
| 81 | 80 |
| 82 // Creates and initializes either |audio_config_| or |video_config_| based on | 81 // Creates and initializes either |audio_config_| or |video_config_| based on |
| 83 // |demuxer_stream_|. | 82 // |demuxer_stream_|. |
| 84 void InitializeDecoderConfig(); | 83 void InitializeDecoderConfig(); |
| 85 | 84 |
| 86 scoped_refptr<base::MessageLoopProxy> message_loop_; | 85 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 86 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_; |
| 87 base::WeakPtr<DecryptingDemuxerStream> weak_this_; |
| 87 | 88 |
| 88 State state_; | 89 State state_; |
| 89 | 90 |
| 90 PipelineStatusCB init_cb_; | 91 PipelineStatusCB init_cb_; |
| 91 ReadCB read_cb_; | 92 ReadCB read_cb_; |
| 92 base::Closure reset_cb_; | 93 base::Closure reset_cb_; |
| 93 | 94 |
| 94 // Pointer to the input demuxer stream that will feed us encrypted buffers. | 95 // Pointer to the input demuxer stream that will feed us encrypted buffers. |
| 95 scoped_refptr<DemuxerStream> demuxer_stream_; | 96 DemuxerStream* demuxer_stream_; |
| 96 | 97 |
| 97 scoped_ptr<AudioDecoderConfig> audio_config_; | 98 scoped_ptr<AudioDecoderConfig> audio_config_; |
| 98 scoped_ptr<VideoDecoderConfig> video_config_; | 99 scoped_ptr<VideoDecoderConfig> video_config_; |
| 99 | 100 |
| 100 // Callback to request/cancel decryptor creation notification. | 101 // Callback to request/cancel decryptor creation notification. |
| 101 SetDecryptorReadyCB set_decryptor_ready_cb_; | 102 SetDecryptorReadyCB set_decryptor_ready_cb_; |
| 102 | 103 |
| 103 Decryptor* decryptor_; | 104 Decryptor* decryptor_; |
| 104 | 105 |
| 105 // The buffer returned by the demuxer that needs to be decrypted. | 106 // The buffer returned by the demuxer that needs to be decrypted. |
| 106 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; | 107 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; |
| 107 | 108 |
| 108 // Indicates the situation where new key is added during pending decryption | 109 // Indicates the situation where new key is added during pending decryption |
| 109 // (in other words, this variable can only be set in state kPendingDecrypt). | 110 // (in other words, this variable can only be set in state kPendingDecrypt). |
| 110 // If this variable is true and kNoKey is returned then we need to try | 111 // If this variable is true and kNoKey is returned then we need to try |
| 111 // decrypting again in case the newly added key is the correct decryption key. | 112 // decrypting again in case the newly added key is the correct decryption key. |
| 112 bool key_added_while_decrypt_pending_; | 113 bool key_added_while_decrypt_pending_; |
| 113 | 114 |
| 114 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); | 115 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 } // namespace media | 118 } // namespace media |
| 118 | 119 |
| 119 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ | 120 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
| OLD | NEW |