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

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: rebase 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
31 // Callback to notify decryptor creation.
32 typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB;
33
34 // Callback to request/cancel decryptor creation notification.
35 // Calling this callback with a non-null callback registers decryptor creation
36 // notification. When the decryptor is created, notification will be sent
37 // through the provided callback.
38 // Calling this callback with a null callback cancels previously registered
39 // decryptor creation notification. Any previously provided callback will be
40 // fired immediately with NULL.
41 typedef base::Callback<void(const DecryptorNotificationCB&)>
42 RequestDecryptorNotificationCB;
43
44 DecryptingDemuxerStream(
45 const MessageLoopFactoryCB& message_loop_factory_cb,
46 const RequestDecryptorNotificationCB& request_decryptor_notification_cb);
47
48 void Initialize(const scoped_refptr<DemuxerStream>& stream,
49 const PipelineStatusCB& status_cb);
50 void Reset(const base::Closure& closure);
51
52 // DemuxerStream implementation.
53 virtual void Read(const ReadCB& read_cb) OVERRIDE;
54 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE;
55 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE;
56 virtual Type type() OVERRIDE;
57 virtual void EnableBitstreamConverter() OVERRIDE;
58
59 protected:
60 virtual ~DecryptingDemuxerStream();
61
62 private:
63 // For a detailed state diagram please see this link: http://goo.gl/8jAok
64 // TODO(xhwang): Add a ASCII state diagram in this file after this class
65 // stabilizes.
66 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream.
67 enum State {
68 kUninitialized = 0,
69 kDecryptorRequested,
70 kIdle,
71 kPendingDemuxerRead,
72 kPendingDecrypt,
73 kWaitingForKey,
74 };
75
76 // Carries out the initialization operation scheduled by Initialize().
77 void DoInitialize(const scoped_refptr<DemuxerStream>& stream,
78 const PipelineStatusCB& status_cb);
79
80 // Callback for DecryptorHost::RequestDecryptor().
81 void SetDecryptor(Decryptor* decryptor);
82
83 // Callback for DemuxerStream::Read().
84 void DecryptBuffer(DemuxerStream::Status status,
85 const scoped_refptr<DecoderBuffer>& buffer);
86
87 // Carries out the buffer decryption operation scheduled by DecryptBuffer().
88 void DoDecryptBuffer(DemuxerStream::Status status,
89 const scoped_refptr<DecoderBuffer>& buffer);
90
91 void DecryptPendingBuffer();
92
93 // Callback for Decryptor::Decrypt().
94 void DeliverBuffer(Decryptor::Status status,
95 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
96
97 // Carries out the frame delivery operation scheduled by DeliverBuffer().
98 void DoDeliverBuffer(Decryptor::Status status,
99 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
100
101 // Callback for the |decryptor_| to notify this object that a new key has been
102 // added.
103 void OnKeyAdded();
104
105 // Resets decoder and calls |reset_cb_|.
106 void DoReset();
107
108 // Returns Decryptor::StreamType converted from |stream_type_|.
109 Decryptor::StreamType GetDecryptorStreamType() const;
110
111 // This is !is_null() iff Initialize() hasn't been called.
112 MessageLoopFactoryCB message_loop_factory_cb_;
113
114 scoped_refptr<base::MessageLoopProxy> message_loop_;
115
116 State state_;
117
118 PipelineStatusCB init_cb_;
119 ReadCB read_cb_;
120 base::Closure reset_cb_;
121
122 // Pointer to the input demuxer stream that will feed us encrypted buffers.
123 scoped_refptr<DemuxerStream> demuxer_stream_;
124
125 Type stream_type_;
126 scoped_ptr<AudioDecoderConfig> audio_config_;
127 scoped_ptr<VideoDecoderConfig> video_config_;
128
129 // Callback to request/cancel decryptor creation notification.
130 RequestDecryptorNotificationCB request_decryptor_notification_cb_;
131
132 Decryptor* decryptor_;
133
134 // The buffer returned by the demuxer that needs to be decrypted.
135 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_;
136
137 // Indicates the situation where new key is added during pending decryption
138 // (in other words, this variable can only be set in state kPendingDecrypt).
139 // If this variable is true and kNoKey is returned then we need to try
140 // decrypting again in case the newly added key is the correct decryption key.
141 bool key_added_while_decrypt_pending_;
142
143 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream);
144 };
145
146 } // namespace media
147
148 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
OLDNEW
« no previous file with comments | « media/filters/decrypting_audio_decoder_unittest.cc ('k') | media/filters/decrypting_demuxer_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698