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

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

Issue 13813016: Remove reference counting from media::Demuxer and friends. (Closed) Base URL: http://git.chromium.org/chromium/src.git@vd_scoped
Patch Set: Created 7 years, 8 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ 5 #ifndef MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
6 #define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ 6 #define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
10 #include "media/base/decryptor.h" 11 #include "media/base/decryptor.h"
11 #include "media/base/demuxer_stream.h" 12 #include "media/base/demuxer_stream.h"
12 13
13 namespace base { 14 namespace base {
14 class MessageLoopProxy; 15 class MessageLoopProxy;
15 } 16 }
16 17
17 namespace media { 18 namespace media {
18 19
19 class DecoderBuffer; 20 class DecoderBuffer;
20 21
21 // Decryptor-based DemuxerStream implementation that converts a potentially 22 // Decryptor-based DemuxerStream implementation that converts a potentially
22 // encrypted demuxer stream to a clear demuxer stream. 23 // encrypted demuxer stream to a clear demuxer stream.
23 // All public APIs and callbacks are trampolined to the |message_loop_| so 24 // All public APIs and callbacks are trampolined to the |message_loop_| so
24 // that no locks are required for thread safety. 25 // that no locks are required for thread safety.
25 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { 26 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream {
26 public: 27 public:
27 DecryptingDemuxerStream( 28 DecryptingDemuxerStream(
28 const scoped_refptr<base::MessageLoopProxy>& message_loop, 29 const scoped_refptr<base::MessageLoopProxy>& message_loop,
29 const SetDecryptorReadyCB& set_decryptor_ready_cb); 30 const SetDecryptorReadyCB& set_decryptor_ready_cb);
31 virtual ~DecryptingDemuxerStream();
30 32
31 void Initialize(const scoped_refptr<DemuxerStream>& stream, 33 void Initialize(DemuxerStream* stream,
32 const PipelineStatusCB& status_cb); 34 const PipelineStatusCB& status_cb);
33 void Reset(const base::Closure& closure); 35 void Reset(const base::Closure& closure);
34 36
35 // DemuxerStream implementation. 37 // DemuxerStream implementation.
36 virtual void Read(const ReadCB& read_cb) OVERRIDE; 38 virtual void Read(const ReadCB& read_cb) OVERRIDE;
37 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; 39 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE;
38 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; 40 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE;
39 virtual Type type() OVERRIDE; 41 virtual Type type() OVERRIDE;
40 virtual void EnableBitstreamConverter() OVERRIDE; 42 virtual void EnableBitstreamConverter() OVERRIDE;
41 43
42 protected:
43 virtual ~DecryptingDemuxerStream();
44
45 private: 44 private:
46 // For a detailed state diagram please see this link: http://goo.gl/8jAok 45 // 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 46 // TODO(xhwang): Add a ASCII state diagram in this file after this class
48 // stabilizes. 47 // stabilizes.
49 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. 48 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream.
50 enum State { 49 enum State {
51 kUninitialized = 0, 50 kUninitialized = 0,
52 kDecryptorRequested, 51 kDecryptorRequested,
53 kIdle, 52 kIdle,
54 kPendingDemuxerRead, 53 kPendingDemuxerRead,
55 kPendingDecrypt, 54 kPendingDecrypt,
56 kWaitingForKey, 55 kWaitingForKey,
57 }; 56 };
58 57
59 // Carries out the initialization operation scheduled by Initialize().
60 void DoInitialize(const scoped_refptr<DemuxerStream>& stream,
61 const PipelineStatusCB& status_cb);
62
63 // Callback for DecryptorHost::RequestDecryptor(). 58 // Callback for DecryptorHost::RequestDecryptor().
64 void SetDecryptor(Decryptor* decryptor); 59 void SetDecryptor(Decryptor* decryptor);
65 60
66 // Callback for DemuxerStream::Read(). 61 // Callback for DemuxerStream::Read().
67 void DecryptBuffer(DemuxerStream::Status status, 62 void DecryptBuffer(DemuxerStream::Status status,
68 const scoped_refptr<DecoderBuffer>& buffer); 63 const scoped_refptr<DecoderBuffer>& buffer);
69 64
70 // Carries out the buffer decryption operation scheduled by DecryptBuffer().
71 void DoDecryptBuffer(DemuxerStream::Status status,
72 const scoped_refptr<DecoderBuffer>& buffer);
73
74 void DecryptPendingBuffer(); 65 void DecryptPendingBuffer();
75 66
76 // Callback for Decryptor::Decrypt(). 67 // Callback for Decryptor::Decrypt().
77 void DeliverBuffer(Decryptor::Status status, 68 void DeliverBuffer(Decryptor::Status status,
78 const scoped_refptr<DecoderBuffer>& decrypted_buffer); 69 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
79 70
80 // Carries out the frame delivery operation scheduled by DeliverBuffer().
81 void DoDeliverBuffer(Decryptor::Status status,
82 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
83
84 // Callback for the |decryptor_| to notify this object that a new key has been 71 // Callback for the |decryptor_| to notify this object that a new key has been
85 // added. 72 // added.
86 void OnKeyAdded(); 73 void OnKeyAdded();
87 74
88 // Resets decoder and calls |reset_cb_|. 75 // Resets decoder and calls |reset_cb_|.
89 void DoReset(); 76 void DoReset();
90 77
91 // Returns Decryptor::StreamType converted from |stream_type_|. 78 // Returns Decryptor::StreamType converted from |stream_type_|.
92 Decryptor::StreamType GetDecryptorStreamType() const; 79 Decryptor::StreamType GetDecryptorStreamType() const;
93 80
94 // Sets |{audio|video}_config_| from |stream|. 81 // Sets |{audio|video}_config_| from |stream|.
95 void SetDecoderConfig(const scoped_refptr<DemuxerStream>& stream); 82 void SetDecoderConfig(DemuxerStream* stream);
96 83
97 scoped_refptr<base::MessageLoopProxy> message_loop_; 84 scoped_refptr<base::MessageLoopProxy> message_loop_;
85 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_;
86 base::WeakPtr<DecryptingDemuxerStream> weak_this_;
98 87
99 State state_; 88 State state_;
100 89
101 PipelineStatusCB init_cb_; 90 PipelineStatusCB init_cb_;
102 ReadCB read_cb_; 91 ReadCB read_cb_;
103 base::Closure reset_cb_; 92 base::Closure reset_cb_;
104 93
105 // Pointer to the input demuxer stream that will feed us encrypted buffers. 94 // Pointer to the input demuxer stream that will feed us encrypted buffers.
106 scoped_refptr<DemuxerStream> demuxer_stream_; 95 DemuxerStream* demuxer_stream_;
107 96
108 Type stream_type_; 97 Type stream_type_;
109 scoped_ptr<AudioDecoderConfig> audio_config_; 98 scoped_ptr<AudioDecoderConfig> audio_config_;
110 scoped_ptr<VideoDecoderConfig> video_config_; 99 scoped_ptr<VideoDecoderConfig> video_config_;
111 100
112 // Callback to request/cancel decryptor creation notification. 101 // Callback to request/cancel decryptor creation notification.
113 SetDecryptorReadyCB set_decryptor_ready_cb_; 102 SetDecryptorReadyCB set_decryptor_ready_cb_;
114 103
115 Decryptor* decryptor_; 104 Decryptor* decryptor_;
116 105
117 // The buffer returned by the demuxer that needs to be decrypted. 106 // The buffer returned by the demuxer that needs to be decrypted.
118 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_; 107 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_;
119 108
120 // Indicates the situation where new key is added during pending decryption 109 // Indicates the situation where new key is added during pending decryption
121 // (in other words, this variable can only be set in state kPendingDecrypt). 110 // (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 111 // 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. 112 // decrypting again in case the newly added key is the correct decryption key.
124 bool key_added_while_decrypt_pending_; 113 bool key_added_while_decrypt_pending_;
125 114
126 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); 115 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream);
127 }; 116 };
128 117
129 } // namespace media 118 } // namespace media
130 119
131 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ 120 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698