#ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
#define MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
#include <jni.h>
#include <string>
#include <vector>
#include "base/android/scoped_java_ref.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "media/base/media_export.h"
#include "media/base/media_keys.h"
#include "url/gurl.h"
class GURL;
namespace media {
class MediaPlayerManager;
class MEDIA_EXPORT MediaDrmBridge : public MediaKeys {
public:
enum SecurityLevel {
SECURITY_LEVEL_NONE = 0,
SECURITY_LEVEL_1 = 1,
SECURITY_LEVEL_3 = 3,
};
typedef base::Callback<void(bool)> ResetCredentialsCB;
virtual ~MediaDrmBridge();
static bool IsAvailable();
static bool IsSecurityLevelSupported(const std::string& key_system,
SecurityLevel security_level);
static bool IsKeySystemSupportedWithType(
const std::string& key_system,
const std::string& container_mime_type);
static bool IsSecureDecoderRequired(SecurityLevel security_level);
static bool RegisterMediaDrmBridge(JNIEnv* env);
static scoped_ptr<MediaDrmBridge> Create(int cdm_id,
const std::string& key_system,
const GURL& security_origin,
MediaPlayerManager* manager);
bool SetSecurityLevel(SecurityLevel security_level);
virtual bool CreateSession(uint32 session_id,
const std::string& content_type,
const uint8* init_data,
int init_data_length) OVERRIDE;
virtual void LoadSession(uint32 session_id,
const std::string& web_session_id) OVERRIDE;
virtual void UpdateSession(uint32 session_id,
const uint8* response,
int response_length) OVERRIDE;
virtual void ReleaseSession(uint32 session_id) OVERRIDE;
base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
void SetMediaCryptoReadyCB(const base::Closure& closure);
void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm);
void OnSessionCreated(JNIEnv* env,
jobject j_media_drm,
jint j_session_id,
jstring j_web_session_id);
void OnSessionMessage(JNIEnv* env,
jobject j_media_drm,
jint j_session_id,
jbyteArray j_message,
jstring j_destination_url);
void OnSessionReady(JNIEnv* env, jobject j_media_drm, jint j_session_id);
void OnSessionClosed(JNIEnv* env, jobject j_media_drm, jint j_session_id);
void OnSessionError(JNIEnv* env, jobject j_media_drm, jint j_session_id);
void ResetDeviceCredentials(const ResetCredentialsCB& callback);
void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success);
bool IsProtectedSurfaceRequired();
int cdm_id() const { return cdm_id_; }
const GURL& security_origin() const { return security_origin_; }
private:
MediaDrmBridge(int cdm_id,
const std::vector<uint8>& scheme_uuid,
const GURL& security_origin,
MediaPlayerManager* manager);
SecurityLevel GetSecurityLevel();
int cdm_id_;
std::vector<uint8> scheme_uuid_;
const GURL security_origin_;
base::android::ScopedJavaGlobalRef<jobject> j_media_drm_;
MediaPlayerManager* manager_;
base::Closure media_crypto_ready_cb_;
ResetCredentialsCB reset_credentials_cb_;
DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge);
};
}
#endif