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

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: needs to add RegisterKeyAddedCB() 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 an encrypted
22 // 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.
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.
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 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.
100 // a new key has been added.
101 void OnKeyAdded();
102
103 // Resets decoder and calls |reset_cb_|.
104 void DoReset();
105
106 // 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
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 // 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.
115 State state_;
116
117 PipelineStatusCB init_cb_;
118 ReadCB read_cb_;
119 base::Closure reset_cb_;
120
121 // Pointer to the input demuxer stream that will feed us encrypted buffers.
122 scoped_refptr<DemuxerStream> demuxer_stream_;
123
124 Type stream_type_;
125 scoped_ptr<AudioDecoderConfig> audio_config_;
126 scoped_ptr<VideoDecoderConfig> video_config_;
127
128 // Callback to request/cancel decryptor creation notification.
129 RequestDecryptorNotificationCB request_decryptor_notification_cb_;
130
131 Decryptor* decryptor_;
132
133 // The buffer returned by the demuxer that needs to be decrypted.
134 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_;
135
136 // Indicates the situation where new key is added during pending decryption
137 // (in other words, this variable can only be set in state kPendingDecrypt).
138 // If this variable is true and kNoKey is returned then we need to try
139 // decrypting again in case the newly added key is the correct decryption key.
140 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.
141
142 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream);
143 };
144
145 } // namespace media
146
147 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698