Home | History | Annotate | Download | only in android
      1 // Copyright (c) 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.
      4 
      5 #ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
      6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
      7 
      8 #include <jni.h>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/android/scoped_java_ref.h"
     13 #include "media/base/media_export.h"
     14 #include "media/base/media_keys.h"
     15 
     16 namespace media {
     17 
     18 class MediaPlayerManager;
     19 
     20 // This class provides DRM services for android EME implementation.
     21 // TODO(qinmin): implement all the functions in this class.
     22 class MEDIA_EXPORT MediaDrmBridge : public MediaKeys {
     23  public:
     24   virtual ~MediaDrmBridge();
     25 
     26   // Returns a MediaDrmBridge instance if |uuid| is supported, or a NULL
     27   // pointer otherwise.
     28   static MediaDrmBridge* Create(int media_keys_id,
     29                                 const std::vector<uint8>& uuid,
     30                                 MediaPlayerManager* manager);
     31 
     32   // Checks whether DRM is available.
     33   static bool IsAvailable();
     34 
     35   // MediaKeys implementations.
     36   virtual bool GenerateKeyRequest(const std::string& type,
     37                                   const uint8* init_data,
     38                                   int init_data_length) OVERRIDE;
     39   virtual void AddKey(const uint8* key, int key_length,
     40                       const uint8* init_data, int init_data_length,
     41                       const std::string& session_id) OVERRIDE;
     42   virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE;
     43 
     44   // Drm related message was received.
     45   void OnDrmEvent(JNIEnv* env, jobject, jstring session_id,
     46                   jint event, jint extra, jstring data);
     47 
     48   // Called after we got the response for GenerateKeyRequest().
     49   void OnKeyMessage(JNIEnv* env, jobject, jstring session_id,
     50                     jbyteArray message, jstring destination_url);
     51 
     52   // Methods to create and release a MediaCrypto object.
     53   base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
     54 
     55   int media_keys_id() const { return media_keys_id_; }
     56 
     57  private:
     58   MediaDrmBridge(int media_keys_id,
     59                  const std::vector<uint8>& uuid,
     60                  MediaPlayerManager* manager);
     61 
     62   // Id of the MediaKeys object.
     63   int media_keys_id_;
     64 
     65   // UUID of the key system.
     66   std::vector<uint8> uuid_;
     67 
     68   // Non-owned pointer.
     69   MediaPlayerManager* manager_;
     70 
     71   DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge);
     72 };
     73 
     74 }  // namespace media
     75 
     76 #endif  // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
     77