blob: 61360ebaceb5f33235cdef782ae9d719ba2bf6a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
#define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "media/base/decryptor.h"
namespace media {
class DecryptorClient;
}
namespace WebKit {
class WebFrame;
class WebMediaPlayerClient;
}
namespace webkit_media {
// A decryptor proxy that creates a real decryptor object on demand and
// forwards decryptor calls to it.
// TODO(xhwang): Currently we don't support run-time switching among decryptor
// objects. Fix this when needed.
class ProxyDecryptor : public media::Decryptor {
public:
ProxyDecryptor(media::DecryptorClient* decryptor_client,
WebKit::WebMediaPlayerClient* web_media_player_client,
WebKit::WebFrame* web_frame);
virtual ~ProxyDecryptor();
// media::Decryptor implementation.
virtual void GenerateKeyRequest(const std::string& key_system,
const uint8* init_data,
int init_data_length) OVERRIDE;
virtual void AddKey(const std::string& key_system,
const uint8* key,
int key_length,
const uint8* init_data,
int init_data_length,
const std::string& session_id) OVERRIDE;
virtual void CancelKeyRequest(const std::string& key_system,
const std::string& session_id) OVERRIDE;
virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted,
const DecryptCB& decrypt_cb) OVERRIDE;
private:
scoped_ptr<media::Decryptor> CreatePpapiDecryptor(
const std::string& key_system);
scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system);
media::DecryptorClient* client_;
// Needed to create the PpapiDecryptor.
WebKit::WebMediaPlayerClient* web_media_player_client_;
WebKit::WebFrame* web_frame_;
// Protects the |decryptor_|. The Decryptor interface specifies that the
// Decrypt() function will be called on the decoder thread and all other
// methods on the renderer thread. The |decryptor_| itself is thread safe
// when this rule is obeyed. This lock is solely to prevent the race condition
// between setting the |decryptor_| in GenerateKeyRequest() and using it in
// Decrypt().
base::Lock lock_;
scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|.
DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor);
};
} // namespace webkit_media
#endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
|