Added histogram for v2 app launch source
[chromium-blink-merge.git] / media / filters / decrypting_demuxer_stream.h
blobb51ce3e8b7a08a9f6b091c0a0ca8973a8824dd1a
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
6 #define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/decryptor.h"
11 #include "media/base/demuxer_stream.h"
13 namespace base {
14 class MessageLoopProxy;
17 namespace media {
19 class DecoderBuffer;
21 // Decryptor-based DemuxerStream implementation that converts a potentially
22 // encrypted demuxer stream to a clear demuxer stream.
23 // All public APIs and callbacks are trampolined to the |message_loop_| so
24 // that no locks are required for thread safety.
25 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream {
26 public:
27 DecryptingDemuxerStream(
28 const scoped_refptr<base::MessageLoopProxy>& message_loop,
29 const SetDecryptorReadyCB& set_decryptor_ready_cb);
31 void Initialize(const scoped_refptr<DemuxerStream>& stream,
32 const PipelineStatusCB& status_cb);
33 void Reset(const base::Closure& closure);
35 // DemuxerStream implementation.
36 virtual void Read(const ReadCB& read_cb) OVERRIDE;
37 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE;
38 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE;
39 virtual Type type() OVERRIDE;
40 virtual void EnableBitstreamConverter() OVERRIDE;
42 protected:
43 virtual ~DecryptingDemuxerStream();
45 private:
46 // 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
48 // stabilizes.
49 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream.
50 enum State {
51 kUninitialized = 0,
52 kDecryptorRequested,
53 kIdle,
54 kPendingDemuxerRead,
55 kPendingDecrypt,
56 kWaitingForKey,
59 // Carries out the initialization operation scheduled by Initialize().
60 void DoInitialize(const scoped_refptr<DemuxerStream>& stream,
61 const PipelineStatusCB& status_cb);
63 // Callback for DecryptorHost::RequestDecryptor().
64 void SetDecryptor(Decryptor* decryptor);
66 // Callback for DemuxerStream::Read().
67 void DecryptBuffer(DemuxerStream::Status status,
68 const scoped_refptr<DecoderBuffer>& buffer);
70 // Carries out the buffer decryption operation scheduled by DecryptBuffer().
71 void DoDecryptBuffer(DemuxerStream::Status status,
72 const scoped_refptr<DecoderBuffer>& buffer);
74 void DecryptPendingBuffer();
76 // Callback for Decryptor::Decrypt().
77 void DeliverBuffer(Decryptor::Status status,
78 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
80 // Carries out the frame delivery operation scheduled by DeliverBuffer().
81 void DoDeliverBuffer(Decryptor::Status status,
82 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
84 // Callback for the |decryptor_| to notify this object that a new key has been
85 // added.
86 void OnKeyAdded();
88 // Resets decoder and calls |reset_cb_|.
89 void DoReset();
91 // Returns Decryptor::StreamType converted from |stream_type_|.
92 Decryptor::StreamType GetDecryptorStreamType() const;
94 // Sets |{audio|video}_config_| from |stream|.
95 void SetDecoderConfig(const scoped_refptr<DemuxerStream>& stream);
97 scoped_refptr<base::MessageLoopProxy> message_loop_;
99 State state_;
101 PipelineStatusCB init_cb_;
102 ReadCB read_cb_;
103 base::Closure reset_cb_;
105 // Pointer to the input demuxer stream that will feed us encrypted buffers.
106 scoped_refptr<DemuxerStream> demuxer_stream_;
108 Type stream_type_;
109 scoped_ptr<AudioDecoderConfig> audio_config_;
110 scoped_ptr<VideoDecoderConfig> video_config_;
112 // Callback to request/cancel decryptor creation notification.
113 SetDecryptorReadyCB set_decryptor_ready_cb_;
115 Decryptor* decryptor_;
117 // The buffer returned by the demuxer that needs to be decrypted.
118 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_;
120 // Indicates the situation where new key is added during pending decryption
121 // (in other words, this variable can only be set in state kPendingDecrypt).
122 // If this variable is true and kNoKey is returned then we need to try
123 // decrypting again in case the newly added key is the correct decryption key.
124 bool key_added_while_decrypt_pending_;
126 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream);
129 } // namespace media
131 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_