Chromium Code Reviews| Index: media/filters/decrypting_demuxer_stream.h |
| diff --git a/media/filters/decrypting_demuxer_stream.h b/media/filters/decrypting_demuxer_stream.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a2546bdbaa9fc4b07e8e42a6e482b6d573d01a48 |
| --- /dev/null |
| +++ b/media/filters/decrypting_demuxer_stream.h |
| @@ -0,0 +1,147 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
| +#define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "media/base/decryptor.h" |
| +#include "media/base/demuxer_stream.h" |
| + |
| +namespace base { |
| +class MessageLoopProxy; |
| +} |
| + |
| +namespace media { |
| + |
| +class DecoderBuffer; |
| + |
| +// Decryptor-based DemuxerStream implementation that converts an encrypted |
| +// demuxer stream to a clear demuxer stream. |
|
ddorwin
2012/11/13 01:08:49
Does it really convert the stream? Is the stream e
xhwang
2012/11/13 21:10:21
Hmm, let's say the video elementary stream is comp
ddorwin
2012/11/13 22:52:33
Not _all_ blocks within the encrypted stream (at l
xhwang
2012/11/14 18:01:52
Right. Added "potentially" to be accurate.
|
| +// All public APIs and callbacks are trampolined to the |message_loop_| so |
| +// that no locks are required for thread safety. |
| +class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { |
| + public: |
| + // Callback to get a message loop. |
| + typedef base::Callback< |
| + scoped_refptr<base::MessageLoopProxy>()> MessageLoopFactoryCB; |
| + // Callback to notify decryptor creation. |
| + typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB; |
| + // Callback to request/cancel decryptor creation notification. |
| + // Calling this callback with a non-null callback registers decryptor creation |
| + // notification. When the decryptor is created, notification will be sent |
| + // through the provided callback. |
| + // Calling this callback with a null callback cancels previously registered |
| + // decryptor creation notification. Any previously provided callback will be |
| + // fired immediately with NULL. |
| + typedef base::Callback<void(const DecryptorNotificationCB&)> |
| + RequestDecryptorNotificationCB; |
| + |
| + DecryptingDemuxerStream( |
| + const MessageLoopFactoryCB& message_loop_factory_cb, |
| + const RequestDecryptorNotificationCB& request_decryptor_notification_cb); |
| + |
| + void Initialize(const scoped_refptr<DemuxerStream>& stream, |
| + const PipelineStatusCB& status_cb); |
| + void Reset(const base::Closure& closure); |
| + |
| + // DemuxerStream implementation. |
| + virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| + virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; |
| + virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; |
| + virtual Type type() OVERRIDE; |
| + virtual void EnableBitstreamConverter() OVERRIDE; |
| + |
| + protected: |
| + virtual ~DecryptingDemuxerStream(); |
| + |
| + private: |
| + // For a detailed state diagram please see this link: http://goo.gl/8jAok |
| + // TODO(xhwang): Add a ASCII state diagram in this file after this class |
| + // stabilizes. |
| + // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. |
| + enum State { |
| + kUninitialized = 0, |
| + kDecryptorRequested, |
| + kIdle, |
| + kPendingDemuxerRead, |
| + kPendingDecrypt, |
| + kWaitingForKey, |
| + }; |
| + |
| + // Carries out the initialization operation scheduled by Initialize(). |
| + void DoInitialize(const scoped_refptr<DemuxerStream>& stream, |
| + const PipelineStatusCB& status_cb); |
| + |
| + // Callback for DecryptorHost::RequestDecryptor(). |
| + void SetDecryptor(Decryptor* decryptor); |
| + |
| + // Callback for DemuxerStream::Read(). |
| + void DecryptBuffer(DemuxerStream::Status status, |
| + const scoped_refptr<DecoderBuffer>& buffer); |
| + |
| + // Carries out the buffer decryption operation scheduled by DecryptBuffer(). |
| + void DoDecryptBuffer(DemuxerStream::Status status, |
| + const scoped_refptr<DecoderBuffer>& buffer); |
| + |
| + void DecryptPendingBuffer(); |
| + |
| + // Callback for Decryptor::Decrypt(). |
| + void DeliverBuffer(Decryptor::Status status, |
| + const scoped_refptr<DecoderBuffer>& decrypted_buffer); |
| + |
| + // Carries out the frame delivery operation scheduled by DeliverBuffer(). |
| + void DoDeliverBuffer(Decryptor::Status status, |
| + const scoped_refptr<DecoderBuffer>& decrypted_buffer); |
| + |
| + // Callback for the |decryptor_| to notify the DecryptingDemuxerStream that |
|
ddorwin
2012/11/13 01:08:49
s/the DecryptingDemuxerStream/this object/
We shou
xhwang
2012/11/13 21:10:21
Done.
|
| + // a new key has been added. |
| + void OnKeyAdded(); |
| + |
| + // Resets decoder and calls |reset_cb_|. |
| + void DoReset(); |
| + |
| + // Returns Decryptor::StreamType converted from |stream_type_|. |
|
ddorwin
2012/11/13 01:08:49
Should we just move Type to a common location in m
xhwang
2012/11/13 21:10:21
Agreed. In another CL? TOTO added in decryptor.h
|
| + Decryptor::StreamType GetDecryptorStreamType() const; |
| + |
| + // This is !is_null() iff Initialize() hasn't been called. |
| + MessageLoopFactoryCB message_loop_factory_cb_; |
| + |
| + scoped_refptr<base::MessageLoopProxy> message_loop_; |
| + |
| + // Current state of the DecryptingDemuxerStream. |
|
ddorwin
2012/11/13 01:08:49
s/DecryptingDemuxerStream/object/
But you can prob
xhwang
2012/11/13 21:10:21
Done.
|
| + State state_; |
| + |
| + PipelineStatusCB init_cb_; |
| + ReadCB read_cb_; |
| + base::Closure reset_cb_; |
| + |
| + // Pointer to the input demuxer stream that will feed us encrypted buffers. |
| + scoped_refptr<DemuxerStream> demuxer_stream_; |
| + |
| + Type stream_type_; |
| + scoped_ptr<AudioDecoderConfig> audio_config_; |
| + scoped_ptr<VideoDecoderConfig> video_config_; |
| + |
| + // Callback to request/cancel decryptor creation notification. |
| + RequestDecryptorNotificationCB request_decryptor_notification_cb_; |
| + |
| + Decryptor* decryptor_; |
| + |
| + // The buffer returned by the demuxer that needs to be decrypted. |
| + scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; |
| + |
| + // Indicates the situation where new key is added during pending decryption |
| + // (in other words, this variable can only be set in state kPendingDecrypt). |
| + // If this variable is true and kNoKey is returned then we need to try |
| + // decrypting again in case the newly added key is the correct decryption key. |
| + bool key_added_while_pending_decrypt_; |
|
ddorwin
2012/11/13 01:08:49
Does "...decrypt_pending_" make more sense? "... w
xhwang
2012/11/13 21:10:21
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |