1 // Copyright 2013 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_BASE_MEDIA_KEYS_H_
6 #define MEDIA_BASE_MEDIA_KEYS_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "media/base/media_export.h"
20 // Performs media key operations.
22 // All key operations are called on the renderer thread. Therefore, these calls
23 // should be fast and nonblocking; key events should be fired asynchronously.
24 class MEDIA_EXPORT MediaKeys
{
26 // Reported to UMA, so never reuse a value!
27 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode
28 // (enforced in webmediaplayer_impl.cc).
32 // The commented v0.1b values below have never been used.
35 // kHardwareChangeError,
37 kMaxKeyError
// Must be last and greater than any legit value.
40 const static uint32 kInvalidSessionId
= 0;
45 // Generates a key request with the |type| and |init_data| provided.
46 // Returns true if generating key request succeeded, false otherwise.
47 // Note: UpdateSession() and ReleaseSession() should only be called after
48 // CreateSession() returns true.
49 // TODO(jrummell): Remove return value when prefixed API is removed.
50 virtual bool CreateSession(uint32 session_id
,
51 const std::string
& type
,
52 const uint8
* init_data
,
53 int init_data_length
) = 0;
55 // Updates a session specified by |session_id| with |response|.
56 virtual void UpdateSession(uint32 session_id
,
57 const uint8
* response
,
58 int response_length
) = 0;
60 // Releases the session specified by |session_id|.
61 virtual void ReleaseSession(uint32 session_id
) = 0;
63 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if
64 // no Decryptor object is associated. The returned object is only guaranteed
65 // to be valid during the MediaKeys' lifetime.
66 virtual Decryptor
* GetDecryptor();
69 DISALLOW_COPY_AND_ASSIGN(MediaKeys
);
72 // Key event callbacks. See the spec for details:
73 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#event-summary
74 typedef base::Callback
<
75 void(uint32 session_id
, const std::string
& web_session_id
)>
78 typedef base::Callback
<void(uint32 session_id
,
79 const std::vector
<uint8
>& message
,
80 const std::string
& destination_url
)>
83 typedef base::Callback
<void(uint32 session_id
)> SessionReadyCB
;
85 typedef base::Callback
<void(uint32 session_id
)> SessionClosedCB
;
87 typedef base::Callback
<void(uint32 session_id
,
88 media::MediaKeys::KeyError error_code
,
89 int system_code
)> SessionErrorCB
;
93 #endif // MEDIA_BASE_MEDIA_KEYS_H_