Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / media / crypto / ppapi_decryptor.h
blobaad28c66b9a396d97449346cefcc4ee21c7ea8a5
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 WEBKIT_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_
6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "media/base/decryptor.h"
13 #include "media/base/video_decoder_config.h"
15 namespace base {
16 class MessageLoopProxy;
19 namespace webkit {
20 namespace ppapi {
21 class ContentDecryptorDelegate;
22 class PluginInstance;
26 namespace webkit_media {
28 // PpapiDecryptor implements media::Decryptor and forwards all calls to the
29 // PluginInstance.
30 // This class should always be created & destroyed on the main renderer thread.
31 class PpapiDecryptor : public media::Decryptor {
32 public:
33 PpapiDecryptor(
34 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance,
35 const media::KeyAddedCB& key_added_cb,
36 const media::KeyErrorCB& key_error_cb,
37 const media::KeyMessageCB& key_message_cb,
38 const media::NeedKeyCB& need_key_cb);
39 virtual ~PpapiDecryptor();
41 // media::Decryptor implementation.
42 virtual bool GenerateKeyRequest(const std::string& key_system,
43 const std::string& type,
44 const uint8* init_data,
45 int init_data_length) OVERRIDE;
46 virtual void AddKey(const std::string& key_system,
47 const uint8* key,
48 int key_length,
49 const uint8* init_data,
50 int init_data_length,
51 const std::string& session_id) OVERRIDE;
52 virtual void CancelKeyRequest(const std::string& key_system,
53 const std::string& session_id) OVERRIDE;
54 virtual void RegisterNewKeyCB(StreamType stream_type,
55 const NewKeyCB& key_added_cb) OVERRIDE;
56 virtual void Decrypt(StreamType stream_type,
57 const scoped_refptr<media::DecoderBuffer>& encrypted,
58 const DecryptCB& decrypt_cb) OVERRIDE;
59 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE;
60 virtual void InitializeAudioDecoder(const media::AudioDecoderConfig& config,
61 const DecoderInitCB& init_cb) OVERRIDE;
62 virtual void InitializeVideoDecoder(const media::VideoDecoderConfig& config,
63 const DecoderInitCB& init_cb) OVERRIDE;
64 virtual void DecryptAndDecodeAudio(
65 const scoped_refptr<media::DecoderBuffer>& encrypted,
66 const AudioDecodeCB& audio_decode_cb) OVERRIDE;
67 virtual void DecryptAndDecodeVideo(
68 const scoped_refptr<media::DecoderBuffer>& encrypted,
69 const VideoDecodeCB& video_decode_cb) OVERRIDE;
70 virtual void ResetDecoder(StreamType stream_type) OVERRIDE;
71 virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE;
73 private:
74 void ReportFailureToCallPlugin(const std::string& key_system,
75 const std::string& session_id);
77 void OnDecoderInitialized(StreamType stream_type, bool success);
79 // Callbacks for |plugin_cdm_delegate_| to fire key events.
80 void KeyAdded(const std::string& key_system, const std::string& session_id);
81 void KeyError(const std::string& key_system,
82 const std::string& session_id,
83 media::Decryptor::KeyError error_code,
84 int system_code);
85 void KeyMessage(const std::string& key_system,
86 const std::string& session_id,
87 const std::string& message,
88 const std::string& default_url);
89 void NeedKey(const std::string& key_system,
90 const std::string& session_id,
91 const std::string& type,
92 scoped_ptr<uint8[]> init_data, int init_data_size);
94 // Hold a reference of the plugin instance to make sure the plugin outlives
95 // the |plugin_cdm_delegate_|. This is needed because |plugin_cdm_delegate_|
96 // is owned by the |plugin_instance_|.
97 scoped_refptr<webkit::ppapi::PluginInstance> plugin_instance_;
99 // Callbacks for firing key events.
100 media::KeyAddedCB key_added_cb_;
101 media::KeyErrorCB key_error_cb_;
102 media::KeyMessageCB key_message_cb_;
103 media::NeedKeyCB need_key_cb_;
105 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate_;
107 scoped_refptr<base::MessageLoopProxy> render_loop_proxy_;
109 DecoderInitCB audio_decoder_init_cb_;
110 DecoderInitCB video_decoder_init_cb_;
111 NewKeyCB new_audio_key_cb_;
112 NewKeyCB new_video_key_cb_;
114 base::WeakPtrFactory<PpapiDecryptor> weak_ptr_factory_;
115 base::WeakPtr<PpapiDecryptor> weak_this_;
117 DISALLOW_COPY_AND_ASSIGN(PpapiDecryptor);
120 } // namespace webkit_media
122 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_