InputImeEventRouter::RegisterImeExtension should register extensions
[chromium-blink-merge.git] / media / filters / decrypting_video_decoder.h
blob6550a2986b23230ecd4b4acfd79fee7c2c029ab8
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 virtual ~DecryptingVideoDecoder();
34 // VideoDecoder implementation.
35 virtual void Initialize(const VideoDecoderConfig& config,
36 bool low_delay,
37 const PipelineStatusCB& status_cb,
38 const OutputCB& output_cb) OVERRIDE;
39 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
40 const DecodeCB& decode_cb) OVERRIDE;
41 virtual void Reset(const base::Closure& closure) OVERRIDE;
43 private:
44 // For a detailed state diagram please see this link: http://goo.gl/8jAok
45 // TODO(xhwang): Add a ASCII state diagram in this file after this class
46 // stabilizes.
47 enum State {
48 kUninitialized = 0,
49 kDecryptorRequested,
50 kPendingDecoderInit,
51 kIdle,
52 kPendingDecode,
53 kWaitingForKey,
54 kDecodeFinished,
55 kError
58 // Callback for DecryptorHost::RequestDecryptor(). |decryptor_attached_cb| is
59 // called when the decryptor has been completely attached to the pipeline.
60 void SetDecryptor(Decryptor* decryptor,
61 const DecryptorAttachedCB& decryptor_attached_cb);
63 // Callback for Decryptor::InitializeVideoDecoder() during initialization.
64 void FinishInitialization(bool success);
66 void DecodePendingBuffer();
68 // Callback for Decryptor::DecryptAndDecodeVideo().
69 void DeliverFrame(int buffer_size,
70 Decryptor::Status status,
71 const scoped_refptr<VideoFrame>& frame);
73 // Callback for the |decryptor_| to notify this object that a new key has been
74 // added.
75 void OnKeyAdded();
77 // Reset decoder and call |reset_cb_|.
78 void DoReset();
80 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
82 State state_;
84 PipelineStatusCB init_cb_;
85 OutputCB output_cb_;
86 DecodeCB decode_cb_;
87 base::Closure reset_cb_;
89 VideoDecoderConfig config_;
91 // Callback to request/cancel decryptor creation notification.
92 SetDecryptorReadyCB set_decryptor_ready_cb_;
94 Decryptor* decryptor_;
96 // The buffer that needs decrypting/decoding.
97 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_;
99 // Indicates the situation where new key is added during pending decode
100 // (in other words, this variable can only be set in state kPendingDecode).
101 // If this variable is true and kNoKey is returned then we need to try
102 // decrypting/decoding again in case the newly added key is the correct
103 // decryption key.
104 bool key_added_while_decode_pending_;
106 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the
107 // matching DecryptCB call (in DoDeliverFrame()).
108 uint32 trace_id_;
110 // NOTE: Weak pointers must be invalidated before all other member variables.
111 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_;
112 base::WeakPtr<DecryptingVideoDecoder> weak_this_;
114 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder);
117 } // namespace media
119 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_