Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(688)

Side by Side Diff: media/filters/decrypting_demuxer_stream.h

Issue 11342031: Add DecryptingDemuxerStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve ddorwin's comments Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
6 #define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
7
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"
12
13 namespace base {
14 class MessageLoopProxy;
15 }
16
17 namespace media {
18
19 class DecoderBuffer;
20
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 // Callback to get a message loop.
28 typedef base::Callback<
29 scoped_refptr<base::MessageLoopProxy>()> MessageLoopFactoryCB;
30 // Callback to notify decryptor creation.
scherkus (not reviewing) 2012/11/14 22:22:30 blank lines between // comments
xhwang 2012/11/15 00:10:00 Done.
31 typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB;
32 // Callback to request/cancel decryptor creation notification.
33 // Calling this callback with a non-null callback registers decryptor creation
34 // notification. When the decryptor is created, notification will be sent
35 // through the provided callback.
36 // Calling this callback with a null callback cancels previously registered
37 // decryptor creation notification. Any previously provided callback will be
38 // fired immediately with NULL.
39 typedef base::Callback<void(const DecryptorNotificationCB&)>
40 RequestDecryptorNotificationCB;
41
42 DecryptingDemuxerStream(
43 const MessageLoopFactoryCB& message_loop_factory_cb,
44 const RequestDecryptorNotificationCB& request_decryptor_notification_cb);
45
46 void Initialize(const scoped_refptr<DemuxerStream>& stream,
47 const PipelineStatusCB& status_cb);
48 void Reset(const base::Closure& closure);
49
50 // DemuxerStream implementation.
51 virtual void Read(const ReadCB& read_cb) OVERRIDE;
52 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE;
53 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE;
54 virtual Type type() OVERRIDE;
55 virtual void EnableBitstreamConverter() OVERRIDE;
56
57 protected:
58 virtual ~DecryptingDemuxerStream();
59
60 private:
61 // For a detailed state diagram please see this link: http://goo.gl/8jAok
62 // TODO(xhwang): Add a ASCII state diagram in this file after this class
63 // stabilizes.
64 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream.
65 enum State {
66 kUninitialized = 0,
67 kDecryptorRequested,
68 kIdle,
69 kPendingDemuxerRead,
70 kPendingDecrypt,
71 kWaitingForKey,
72 };
73
74 // Carries out the initialization operation scheduled by Initialize().
75 void DoInitialize(const scoped_refptr<DemuxerStream>& stream,
76 const PipelineStatusCB& status_cb);
77
78 // Callback for DecryptorHost::RequestDecryptor().
79 void SetDecryptor(Decryptor* decryptor);
80
81 // Callback for DemuxerStream::Read().
82 void DecryptBuffer(DemuxerStream::Status status,
83 const scoped_refptr<DecoderBuffer>& buffer);
84
85 // Carries out the buffer decryption operation scheduled by DecryptBuffer().
86 void DoDecryptBuffer(DemuxerStream::Status status,
87 const scoped_refptr<DecoderBuffer>& buffer);
88
89 void DecryptPendingBuffer();
90
91 // Callback for Decryptor::Decrypt().
92 void DeliverBuffer(Decryptor::Status status,
93 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
94
95 // Carries out the frame delivery operation scheduled by DeliverBuffer().
96 void DoDeliverBuffer(Decryptor::Status status,
97 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
98
99 // Callback for the |decryptor_| to notify this object that a new key has been
100 // added.
101 void OnKeyAdded();
102
103 // Resets decoder and calls |reset_cb_|.
104 void DoReset();
105
106 // Returns Decryptor::StreamType converted from |stream_type_|.
107 Decryptor::StreamType GetDecryptorStreamType() const;
108
109 // This is !is_null() iff Initialize() hasn't been called.
110 MessageLoopFactoryCB message_loop_factory_cb_;
111
112 scoped_refptr<base::MessageLoopProxy> message_loop_;
113
114 State state_;
115
116 PipelineStatusCB init_cb_;
117 ReadCB read_cb_;
118 base::Closure reset_cb_;
119
120 // Pointer to the input demuxer stream that will feed us encrypted buffers.
121 scoped_refptr<DemuxerStream> demuxer_stream_;
122
123 Type stream_type_;
124 scoped_ptr<AudioDecoderConfig> audio_config_;
125 scoped_ptr<VideoDecoderConfig> video_config_;
126
127 // Callback to request/cancel decryptor creation notification.
128 RequestDecryptorNotificationCB request_decryptor_notification_cb_;
129
130 Decryptor* decryptor_;
131
132 // The buffer returned by the demuxer that needs to be decrypted.
133 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_;
134
135 // Indicates the situation where new key is added during pending decryption
136 // (in other words, this variable can only be set in state kPendingDecrypt).
137 // If this variable is true and kNoKey is returned then we need to try
138 // decrypting again in case the newly added key is the correct decryption key.
139 bool key_added_while_decrypt_pending_;
140
141 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream);
142 };
143
144 } // namespace media
145
146 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698