hunspell: Cleanup to fix the header include guards under google/ directory.
[chromium-blink-merge.git] / media / filters / decrypting_demuxer_stream.h
bloba04709ea395d57778f521b54141f3e1da5261e8a
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.
5 #ifndef MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
6 #define MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "media/base/audio_decoder_config.h"
12 #include "media/base/decryptor.h"
13 #include "media/base/demuxer_stream.h"
14 #include "media/base/pipeline_status.h"
15 #include "media/base/video_decoder_config.h"
17 namespace base {
18 class SingleThreadTaskRunner;
21 namespace media {
23 class DecoderBuffer;
24 class MediaLog;
26 // Decryptor-based DemuxerStream implementation that converts a potentially
27 // encrypted demuxer stream to a clear demuxer stream.
28 // All public APIs and callbacks are trampolined to the |task_runner_| so
29 // that no locks are required for thread safety.
30 class MEDIA_EXPORT DecryptingDemuxerStream : public DemuxerStream {
31 public:
32 DecryptingDemuxerStream(
33 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
34 const scoped_refptr<MediaLog>& media_log,
35 const SetDecryptorReadyCB& set_decryptor_ready_cb,
36 const base::Closure& waiting_for_decryption_key_cb);
38 // Cancels all pending operations immediately and fires all pending callbacks.
39 ~DecryptingDemuxerStream() override;
41 void Initialize(DemuxerStream* stream,
42 const PipelineStatusCB& status_cb);
44 // Cancels all pending operations and fires all pending callbacks. If in
45 // kPendingDemuxerRead or kPendingDecrypt state, waits for the pending
46 // operation to finish before satisfying |closure|. Sets the state to
47 // kUninitialized if |this| hasn't been initialized, or to kIdle otherwise.
48 void Reset(const base::Closure& closure);
50 // Returns the name of this class for logging purpose.
51 std::string GetDisplayName() const;
53 // DemuxerStream implementation.
54 void Read(const ReadCB& read_cb) override;
55 AudioDecoderConfig audio_decoder_config() override;
56 VideoDecoderConfig video_decoder_config() override;
57 Type type() const override;
58 Liveness liveness() const override;
59 void EnableBitstreamConverter() override;
60 bool SupportsConfigChanges() override;
61 VideoRotation video_rotation() override;
63 private:
64 // For a detailed state diagram please see this link: http://goo.gl/8jAok
65 // TODO(xhwang): Add a ASCII state diagram in this file after this class
66 // stabilizes.
67 // TODO(xhwang): Update this diagram for DecryptingDemuxerStream.
68 enum State {
69 kUninitialized = 0,
70 kDecryptorRequested,
71 kIdle,
72 kPendingDemuxerRead,
73 kPendingDecrypt,
74 kWaitingForKey
77 // Callback for DecryptorHost::RequestDecryptor(). |decryptor_attached_cb| is
78 // called when the decryptor has been completely attached to the pipeline.
79 void SetDecryptor(Decryptor* decryptor,
80 const DecryptorAttachedCB& decryptor_attached_cb);
82 // Callback for DemuxerStream::Read().
83 void DecryptBuffer(DemuxerStream::Status status,
84 const scoped_refptr<DecoderBuffer>& buffer);
86 void DecryptPendingBuffer();
88 // Callback for Decryptor::Decrypt().
89 void DeliverBuffer(Decryptor::Status status,
90 const scoped_refptr<DecoderBuffer>& decrypted_buffer);
92 // Callback for the |decryptor_| to notify this object that a new key has been
93 // added.
94 void OnKeyAdded();
96 // Resets decoder and calls |reset_cb_|.
97 void DoReset();
99 // Returns Decryptor::StreamType converted from |stream_type_|.
100 Decryptor::StreamType GetDecryptorStreamType() const;
102 // Creates and initializes either |audio_config_| or |video_config_| based on
103 // |demuxer_stream_|.
104 void InitializeDecoderConfig();
106 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
108 scoped_refptr<MediaLog> media_log_;
110 State state_;
112 PipelineStatusCB init_cb_;
113 ReadCB read_cb_;
114 base::Closure reset_cb_;
115 base::Closure waiting_for_decryption_key_cb_;
117 // Pointer to the input demuxer stream that will feed us encrypted buffers.
118 DemuxerStream* demuxer_stream_;
120 AudioDecoderConfig audio_config_;
121 VideoDecoderConfig video_config_;
123 // Callback to request/cancel decryptor creation notification.
124 SetDecryptorReadyCB set_decryptor_ready_cb_;
126 Decryptor* decryptor_;
128 // The buffer returned by the demuxer that needs to be decrypted.
129 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decrypt_;
131 // Indicates the situation where new key is added during pending decryption
132 // (in other words, this variable can only be set in state kPendingDecrypt).
133 // If this variable is true and kNoKey is returned then we need to try
134 // decrypting again in case the newly added key is the correct decryption key.
135 bool key_added_while_decrypt_pending_;
137 base::WeakPtr<DecryptingDemuxerStream> weak_this_;
138 base::WeakPtrFactory<DecryptingDemuxerStream> weak_factory_;
140 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStream);
143 } // namespace media
145 #endif // MEDIA_FILTERS_DECRYPTING_DEMUXER_STREAM_H_