Revert of Set defaultPageScaleLimits before setIgnoreViewportTagScaleLimits (patchset...
[chromium-blink-merge.git] / media / filters / decrypting_video_decoder.h
blob8e40502cb13f83541708a637e06846bdf4f4c9e9
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_VIDEO_DECODER_H_
6 #define MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "media/base/decryptor.h"
11 #include "media/base/video_decoder.h"
12 #include "media/base/video_decoder_config.h"
14 namespace base {
15 class SingleThreadTaskRunner;
18 namespace media {
20 class DecoderBuffer;
21 class Decryptor;
23 // Decryptor-based VideoDecoder implementation that can decrypt and decode
24 // encrypted video buffers and return decrypted and decompressed video frames.
25 // All public APIs and callbacks are trampolined to the |task_runner_| so
26 // that no locks are required for thread safety.
27 class MEDIA_EXPORT DecryptingVideoDecoder : public VideoDecoder {
28 public:
29 DecryptingVideoDecoder(
30 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
31 const SetDecryptorReadyCB& set_decryptor_ready_cb);
32 ~DecryptingVideoDecoder() override;
34 // VideoDecoder implementation.
35 std::string GetDisplayName() const override;
36 void Initialize(const VideoDecoderConfig& config,
37 bool low_delay,
38 const PipelineStatusCB& status_cb,
39 const OutputCB& output_cb) override;
40 void Decode(const scoped_refptr<DecoderBuffer>& buffer,
41 const DecodeCB& decode_cb) override;
42 void Reset(const base::Closure& closure) override;
44 static const char kDecoderName[];
46 private:
47 // For a detailed state diagram please see this link: http://goo.gl/8jAok
48 // TODO(xhwang): Add a ASCII state diagram in this file after this class
49 // stabilizes.
50 enum State {
51 kUninitialized = 0,
52 kDecryptorRequested,
53 kPendingDecoderInit,
54 kIdle,
55 kPendingDecode,
56 kWaitingForKey,
57 kDecodeFinished,
58 kError
61 // Callback for DecryptorHost::RequestDecryptor(). |decryptor_attached_cb| is
62 // called when the decryptor has been completely attached to the pipeline.
63 void SetDecryptor(Decryptor* decryptor,
64 const DecryptorAttachedCB& decryptor_attached_cb);
66 // Callback for Decryptor::InitializeVideoDecoder() during initialization.
67 void FinishInitialization(bool success);
69 void DecodePendingBuffer();
71 // Callback for Decryptor::DecryptAndDecodeVideo().
72 void DeliverFrame(int buffer_size,
73 Decryptor::Status status,
74 const scoped_refptr<VideoFrame>& frame);
76 // Callback for the |decryptor_| to notify this object that a new key has been
77 // added.
78 void OnKeyAdded();
80 // Reset decoder and call |reset_cb_|.
81 void DoReset();
83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
85 State state_;
87 PipelineStatusCB init_cb_;
88 OutputCB output_cb_;
89 DecodeCB decode_cb_;
90 base::Closure reset_cb_;
92 VideoDecoderConfig config_;
94 // Callback to request/cancel decryptor creation notification.
95 SetDecryptorReadyCB set_decryptor_ready_cb_;
97 Decryptor* decryptor_;
99 // The buffer that needs decrypting/decoding.
100 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_;
102 // Indicates the situation where new key is added during pending decode
103 // (in other words, this variable can only be set in state kPendingDecode).
104 // If this variable is true and kNoKey is returned then we need to try
105 // decrypting/decoding again in case the newly added key is the correct
106 // decryption key.
107 bool key_added_while_decode_pending_;
109 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the
110 // matching DecryptCB call (in DoDeliverFrame()).
111 uint32 trace_id_;
113 base::WeakPtr<DecryptingVideoDecoder> weak_this_;
114 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_;
116 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder);
119 } // namespace media
121 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_