Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / filters / decrypting_video_decoder.h
blob80b3b814bf5a4f904897c635879ecf5030dcbccf
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;
22 class MediaLog;
24 // Decryptor-based VideoDecoder implementation that can decrypt and decode
25 // encrypted video buffers and return decrypted and decompressed video frames.
26 // All public APIs and callbacks are trampolined to the |task_runner_| so
27 // that no locks are required for thread safety.
28 class MEDIA_EXPORT DecryptingVideoDecoder : public VideoDecoder {
29 public:
30 DecryptingVideoDecoder(
31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
32 const scoped_refptr<MediaLog>& media_log,
33 const SetDecryptorReadyCB& set_decryptor_ready_cb,
34 const base::Closure& waiting_for_decryption_key_cb);
35 ~DecryptingVideoDecoder() override;
37 // VideoDecoder implementation.
38 std::string GetDisplayName() const override;
39 void Initialize(const VideoDecoderConfig& config,
40 bool low_delay,
41 const InitCB& init_cb,
42 const OutputCB& output_cb) override;
43 void Decode(const scoped_refptr<DecoderBuffer>& buffer,
44 const DecodeCB& decode_cb) override;
45 void Reset(const base::Closure& closure) override;
47 static const char kDecoderName[];
49 private:
50 // For a detailed state diagram please see this link: http://goo.gl/8jAok
51 // TODO(xhwang): Add a ASCII state diagram in this file after this class
52 // stabilizes.
53 enum State {
54 kUninitialized = 0,
55 kDecryptorRequested,
56 kPendingDecoderInit,
57 kIdle,
58 kPendingDecode,
59 kWaitingForKey,
60 kDecodeFinished,
61 kError
64 // Callback for DecryptorHost::RequestDecryptor(). |decryptor_attached_cb| is
65 // called when the decryptor has been completely attached to the pipeline.
66 void SetDecryptor(Decryptor* decryptor,
67 const DecryptorAttachedCB& decryptor_attached_cb);
69 // Callback for Decryptor::InitializeVideoDecoder() during initialization.
70 void FinishInitialization(bool success);
72 void DecodePendingBuffer();
74 // Callback for Decryptor::DecryptAndDecodeVideo().
75 void DeliverFrame(int buffer_size,
76 Decryptor::Status status,
77 const scoped_refptr<VideoFrame>& frame);
79 // Callback for the |decryptor_| to notify this object that a new key has been
80 // added.
81 void OnKeyAdded();
83 // Reset decoder and call |reset_cb_|.
84 void DoReset();
86 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
88 scoped_refptr<MediaLog> media_log_;
90 State state_;
92 InitCB init_cb_;
93 OutputCB output_cb_;
94 DecodeCB decode_cb_;
95 base::Closure reset_cb_;
96 base::Closure waiting_for_decryption_key_cb_;
98 VideoDecoderConfig config_;
100 // Callback to request/cancel decryptor creation notification.
101 SetDecryptorReadyCB set_decryptor_ready_cb_;
103 Decryptor* decryptor_;
105 // The buffer that needs decrypting/decoding.
106 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_;
108 // Indicates the situation where new key is added during pending decode
109 // (in other words, this variable can only be set in state kPendingDecode).
110 // If this variable is true and kNoKey is returned then we need to try
111 // decrypting/decoding again in case the newly added key is the correct
112 // decryption key.
113 bool key_added_while_decode_pending_;
115 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the
116 // matching DecryptCB call (in DoDeliverFrame()).
117 uint32 trace_id_;
119 base::WeakPtr<DecryptingVideoDecoder> weak_this_;
120 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_;
122 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder);
125 } // namespace media
127 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_