DrmPlugin.cpp revision d072c909d87f8150433860f6de4c11df6e09e2f9
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17//#define LOG_NDEBUG 0 18#define LOG_TAG "ClearKeyCryptoPlugin" 19#include <utils/Log.h> 20 21#include <media/stagefright/MediaErrors.h> 22#include <utils/StrongPointer.h> 23 24#include "DrmPlugin.h" 25 26#include "Session.h" 27 28namespace clearkeydrm { 29 30using android::sp; 31 32status_t DrmPlugin::openSession(Vector<uint8_t>& sessionId) { 33 sp<Session> session = mSessionLibrary->createSession(); 34 sessionId = session->sessionId(); 35 return android::OK; 36} 37 38status_t DrmPlugin::closeSession(const Vector<uint8_t>& sessionId) { 39 sp<Session> session = mSessionLibrary->findSession(sessionId); 40 mSessionLibrary->destroySession(session); 41 return android::OK; 42} 43 44status_t DrmPlugin::getKeyRequest( 45 const Vector<uint8_t>& scope, 46 const Vector<uint8_t>& initData, 47 const String8& initDataType, 48 KeyType keyType, 49 const KeyedVector<String8, String8>& optionalParameters, 50 Vector<uint8_t>& request, 51 String8& defaultUrl, 52 DrmPlugin::KeyRequestType *keyRequestType) { 53 UNUSED(optionalParameters); 54 if (keyType != kKeyType_Streaming) { 55 return android::ERROR_DRM_CANNOT_HANDLE; 56 } 57 *keyRequestType = DrmPlugin::kKeyRequestType_Initial; 58 sp<Session> session = mSessionLibrary->findSession(scope); 59 defaultUrl.clear(); 60 return session->getKeyRequest(initData, initDataType, &request); 61} 62 63status_t DrmPlugin::provideKeyResponse( 64 const Vector<uint8_t>& scope, 65 const Vector<uint8_t>& response, 66 Vector<uint8_t>& keySetId) { 67 sp<Session> session = mSessionLibrary->findSession(scope); 68 status_t res = session->provideKeyResponse(response); 69 if (res == android::OK) { 70 keySetId.clear(); 71 } 72 return res; 73} 74 75status_t DrmPlugin::getPropertyString( 76 const String8& name, String8& value) const { 77 if (name == "vendor") { 78 value = "Google"; 79 } else if (name == "version") { 80 value = "1.0"; 81 } else if (name == "description") { 82 value = "ClearKey CDM"; 83 } else if (name == "algorithms") { 84 value = ""; 85 } else { 86 ALOGE("App requested unknown string property %s", name.string()); 87 return android::ERROR_DRM_CANNOT_HANDLE; 88 } 89 return android::OK; 90} 91 92} // namespace clearkeydrm 93