Correct gfx dependency for cast_receiver_app.
[chromium-blink-merge.git] / media / filters / decrypting_video_decoder.h
bloba2a952844d95225a50ed1cb7c04f8ca728149ce6
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 const base::Closure& waiting_for_decryption_key_cb);
33 ~DecryptingVideoDecoder() override;
35 // VideoDecoder implementation.
36 std::string GetDisplayName() const override;
37 void Initialize(const VideoDecoderConfig& config,
38 bool low_delay,
39 const PipelineStatusCB& status_cb,
40 const OutputCB& output_cb) override;
41 void Decode(const scoped_refptr<DecoderBuffer>& buffer,
42 const DecodeCB& decode_cb) override;
43 void Reset(const base::Closure& closure) override;
45 static const char kDecoderName[];
47 private:
48 // For a detailed state diagram please see this link: http://goo.gl/8jAok
49 // TODO(xhwang): Add a ASCII state diagram in this file after this class
50 // stabilizes.
51 enum State {
52 kUninitialized = 0,
53 kDecryptorRequested,
54 kPendingDecoderInit,
55 kIdle,
56 kPendingDecode,
57 kWaitingForKey,
58 kDecodeFinished,
59 kError
62 // Callback for DecryptorHost::RequestDecryptor(). |decryptor_attached_cb| is
63 // called when the decryptor has been completely attached to the pipeline.
64 void SetDecryptor(Decryptor* decryptor,
65 const DecryptorAttachedCB& decryptor_attached_cb);
67 // Callback for Decryptor::InitializeVideoDecoder() during initialization.
68 void FinishInitialization(bool success);
70 void DecodePendingBuffer();
72 // Callback for Decryptor::DecryptAndDecodeVideo().
73 void DeliverFrame(int buffer_size,
74 Decryptor::Status status,
75 const scoped_refptr<VideoFrame>& frame);
77 // Callback for the |decryptor_| to notify this object that a new key has been
78 // added.
79 void OnKeyAdded();
81 // Reset decoder and call |reset_cb_|.
82 void DoReset();
84 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
86 State state_;
88 PipelineStatusCB init_cb_;
89 OutputCB output_cb_;
90 DecodeCB decode_cb_;
91 base::Closure reset_cb_;
92 base::Closure waiting_for_decryption_key_cb_;
94 VideoDecoderConfig config_;
96 // Callback to request/cancel decryptor creation notification.
97 SetDecryptorReadyCB set_decryptor_ready_cb_;
99 Decryptor* decryptor_;
101 // The buffer that needs decrypting/decoding.
102 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_;
104 // Indicates the situation where new key is added during pending decode
105 // (in other words, this variable can only be set in state kPendingDecode).
106 // If this variable is true and kNoKey is returned then we need to try
107 // decrypting/decoding again in case the newly added key is the correct
108 // decryption key.
109 bool key_added_while_decode_pending_;
111 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the
112 // matching DecryptCB call (in DoDeliverFrame()).
113 uint32 trace_id_;
115 base::WeakPtr<DecryptingVideoDecoder> weak_this_;
116 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_;
118 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder);
121 } // namespace media
123 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_