OLD | NEW |
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 "base/memory/weak_ptr.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // Decryptor-based DemuxerStream implementation that converts a potentially | 25 // Decryptor-based DemuxerStream implementation that converts a potentially |
26 // encrypted demuxer stream to a clear demuxer stream. | 26 // encrypted demuxer stream to a clear demuxer stream. |
27 // All public APIs and callbacks are trampolined to the |task_runner_| so | 27 // All public APIs and callbacks are trampolined to the |task_runner_| so |
28 // that no locks are required for thread safety. | 28 // that no locks are required for thread safety. |
29 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { | 29 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream { |
30 public: | 30 public: |
31 DecryptingDemuxerStream( | 31 DecryptingDemuxerStream( |
32 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 32 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
33 const SetDecryptorReadyCB& set_decryptor_ready_cb); | 33 const SetDecryptorReadyCB& set_decryptor_ready_cb); |
| 34 |
| 35 // Cancels all pending operations immediately and fires all pending callbacks. |
34 virtual ~DecryptingDemuxerStream(); | 36 virtual ~DecryptingDemuxerStream(); |
35 | 37 |
36 void Initialize(DemuxerStream* stream, | 38 void Initialize(DemuxerStream* stream, |
37 const PipelineStatusCB& status_cb); | 39 const PipelineStatusCB& status_cb); |
38 | 40 |
39 // Cancels all pending operations and fires all pending callbacks. If in | 41 // Cancels all pending operations and fires all pending callbacks. If in |
40 // kPendingDemuxerRead or kPendingDecrypt state, waits for the pending | 42 // kPendingDemuxerRead or kPendingDecrypt state, waits for the pending |
41 // operation to finish before satisfying |closure|. Sets the state to | 43 // operation to finish before satisfying |closure|. Sets the state to |
42 // kUninitialized if |this| hasn't been initialized, or to kIdle otherwise. | 44 // kUninitialized if |this| hasn't been initialized, or to kIdle otherwise. |
43 void Reset(const base::Closure& closure); | 45 void Reset(const base::Closure& closure); |
44 | 46 |
45 // Cancels all pending operations immediately and fires all pending callbacks | |
46 // and sets the state to kStopped. Does NOT wait for any pending operations. | |
47 // Note: During the teardown process, media pipeline will be waiting on the | |
48 // render main thread. If a Decryptor depends on the render main thread | |
49 // (e.g. PpapiDecryptor), the pending DecryptCB would not be satisfied. | |
50 void Stop(); | |
51 | |
52 // DemuxerStream implementation. | 47 // DemuxerStream implementation. |
53 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 48 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
54 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; | 49 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; |
55 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; | 50 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; |
56 virtual Type type() OVERRIDE; | 51 virtual Type type() OVERRIDE; |
57 virtual void EnableBitstreamConverter() OVERRIDE; | 52 virtual void EnableBitstreamConverter() OVERRIDE; |
58 virtual bool SupportsConfigChanges() OVERRIDE; | 53 virtual bool SupportsConfigChanges() OVERRIDE; |
59 virtual VideoRotation video_rotation() OVERRIDE; | 54 virtual VideoRotation video_rotation() OVERRIDE; |
60 | 55 |
61 private: | 56 private: |
62 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 57 // For a detailed state diagram please see this link: http://goo.gl/8jAok |
63 // TODO(xhwang): Add a ASCII state diagram in this file after this class | 58 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
64 // stabilizes. | 59 // stabilizes. |
65 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. | 60 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream. |
66 enum State { | 61 enum State { |
67 kUninitialized = 0, | 62 kUninitialized = 0, |
68 kDecryptorRequested, | 63 kDecryptorRequested, |
69 kIdle, | 64 kIdle, |
70 kPendingDemuxerRead, | 65 kPendingDemuxerRead, |
71 kPendingDecrypt, | 66 kPendingDecrypt, |
72 kWaitingForKey, | 67 kWaitingForKey |
73 kStopped | |
74 }; | 68 }; |
75 | 69 |
76 // Callback for DecryptorHost::RequestDecryptor(). | 70 // Callback for DecryptorHost::RequestDecryptor(). |
77 void SetDecryptor(Decryptor* decryptor); | 71 void SetDecryptor(Decryptor* decryptor); |
78 | 72 |
79 // Callback for DemuxerStream::Read(). | 73 // Callback for DemuxerStream::Read(). |
80 void DecryptBuffer(DemuxerStream::Status status, | 74 void DecryptBuffer(DemuxerStream::Status status, |
81 const scoped_refptr<DecoderBuffer>& buffer); | 75 const scoped_refptr<DecoderBuffer>& buffer); |
82 | 76 |
83 void DecryptPendingBuffer(); | 77 void DecryptPendingBuffer(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // NOTE: Weak pointers must be invalidated before all other member variables. | 125 // NOTE: Weak pointers must be invalidated before all other member variables. |
132 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_; | 126 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_; |
133 base::WeakPtr<DecryptingDemuxerStream> weak_this_; | 127 base::WeakPtr<DecryptingDemuxerStream> weak_this_; |
134 | 128 |
135 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); | 129 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream); |
136 }; | 130 }; |
137 | 131 |
138 } // namespace media | 132 } // namespace media |
139 | 133 |
140 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ | 134 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_ |
OLD | NEW |